Untitled
unknown
plain_text
a month ago
4.0 kB
16
Indexable
index.html <!DOCTYPE html> <html> <head> <title>Start Page</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form action="add" method="post"> <input type="text" name="t1" id="t1"><br> <input type="text" name="t2" id="t2"><br> <input type="submit" value="+"> </form> </body> </html> add.java (servlet) import java.io.IOException; import java.io.PrintWriter; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import myejb.MYBEANS; public class add extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { int a =Integer.parseInt(request.getParameter("t1")); int b =Integer.parseInt(request.getParameter("t2")); MYBEANS mb= new MYBEANS(); mb.setA(a); mb.setB(b); mb.sum(); int k= mb.getC(); out.println("result:"+k); // /* TODO output your page here. You may use following sample code. */ // out.println("<!DOCTYPE html>"); // out.println("<html>"); // out.println("<head>"); // out.println("<title>Servlet add</title>"); // out.println("</head>"); // out.println("<body>"); // out.println("<h1>Servlet add at " + request.getContextPath() + "</h1>"); // out.println("</body>"); // out.println("</html>"); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> } MYBEANS.java in myejb package myejb package khudse bnao /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package myejb; public class MYBEANS { private int a,b,c; public int getA() { return a; } public void setA(int a) { this.a = a; } public int getB() { return b; } public void setB(int b) { this.b = b; } public int getC() { return c; } public void setC(int c) { this.c = c; } public void sum(){ c=a+b; } }
Editor is loading...
Leave a Comment