CalculoJuros/src/java/servlets/jurosSimples.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
@Override
    protected void doGet(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>Servlet jurosSimples</title>");            
            out.println("</head>");
            out.println("<body>");
            try {                
                String val = request.getParameter("valor");
                String percent = request.getParameter("juros");
                String months = request.getParameter("meses");
                double dval = Double.parseDouble(val);
                double dpercent = Double.parseDouble(percent);
                int dmonths = Integer.parseInt(months);
                double resultado = (dval * (1 + (dpercent / 100)*dmonths));                
                out.print("<h4>Juros simples</h4>");
                out.print("<h4><b>Resultado</b>: "+resultado+"</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>");
        }
    }
@ Override protected void doGet ( 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>Servlet jurosSimples</title>" ) ; out . println ( "</head>" ) ; out . println ( "<body>" ) ; try { String val = request . getParameter ( "valor" ) ; String percent = request . getParameter ( "juros" ) ; String months = request . getParameter ( "meses" ) ; double dval = Double . parseDouble ( val ) ; double dpercent = Double . parseDouble ( percent ) ; int dmonths = Integer . parseInt ( months ) ; double resultado = ( dval * ( 1 + ( dpercent / 100 ) * dmonths ) ) ; out . print ( "<h4>Juros simples</h4>" ) ; out . print ( "<h4><b>Resultado</b>: " + resultado + "</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 .