Projeto_Aula03-16-08/src/java/servlets/SomaServlet.java
/**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
Processes requests for both HTTP GET and POST
methods.

@param request servlet request
@param response servlet response
@throws ServletException if a servlet-specific error occurs
@throws IOException if an I/O error occurs
Processes requests for both HTTP GET and POST methods . @param request servlet request @param response servlet response @throws ServletException if a servlet - specific error occurs @throws IOException if an I / O error occurs
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>JavaEE - Servlets</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>JavaEE</h1>");
            out.println("<h2>Servlets</h2>");            
            out.println("<h3>Soma</h3>");           
            try {
                double n1 = Double.parseDouble(request.getParameter("n1"));
                out.println("<h4><b>N1</b>: "+n1+"</h4>"); 
                double n2 = Double.parseDouble(request.getParameter("n2"));
                out.println("<h4><b>N1</b>: "+n2+"</h4>"); 
                out.println("<hr/>");
                out.println("<h4><b>Soma</b>: "+(n1+n2)+"</h4>"); 
            } catch (Exception ex) {
                out.println("<p style='color:red'>"+ex.getMessage()+"</p>");
            }
            out.println("<h3><a href='index.html'>Voltar</a></h3>");
            out.println("</body>");
            out.println("</html>");
        }
    }
protected void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { response . setContentType ( "text/html;charset=UTF-8" ) ; try ( PrintWriter out = response . getWriter ( ) ) { /* TODO output your page here. You may use following sample code. */ out . println ( "<!DOCTYPE html>" ) ; out . println ( "<html>" ) ; out . println ( "<head>" ) ; out . println ( "<title>JavaEE - Servlets</title>" ) ; out . println ( "</head>" ) ; out . println ( "<body>" ) ; out . println ( "<h1>JavaEE</h1>" ) ; out . println ( "<h2>Servlets</h2>" ) ; out . println ( "<h3>Soma</h3>" ) ; try { double n1 = Double . parseDouble ( request . getParameter ( "n1" ) ) ; out . println ( "<h4><b>N1</b>: " + n1 + "</h4>" ) ; double n2 = Double . parseDouble ( request . getParameter ( "n2" ) ) ; out . println ( "<h4><b>N1</b>: " + n2 + "</h4>" ) ; out . println ( "<hr/>" ) ; out . println ( "<h4><b>Soma</b>: " + ( n1 + n2 ) + "</h4>" ) ; } catch ( Exception ex ) { out . println ( "<p style='color:red'>" + ex . getMessage ( ) + "</p>" ) ; } out . println ( "<h3><a href='index.html'>Voltar</a></h3>" ) ; out . println ( "</body>" ) ; out . println ( "</html>" ) ; } }
Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 methods.
Processes requests for both HTTP <code > GET< / code > and <code > POST< / code > methods .