0% found this document useful (0 votes)
25 views2 pages

Entradadedatos

This document contains code for a servlet application that calculates income tax. It includes an HTML form to input a salary amount, and a Java servlet that parses the salary parameter, calculates the tax, and returns an HTML page displaying the results. The servlet uses the POST method to process the form submission and retrieve the salary field, then prints the results.

Uploaded by

Orlin23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Entradadedatos

This document contains code for a servlet application that calculates income tax. It includes an HTML form to input a salary amount, and a Java servlet that parses the salary parameter, calculates the tax, and returns an HTML page displaying the results. The servlet uses the POST method to process the form submission and retrieve the salary field, then prints the results.

Uploaded by

Orlin23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Materia: programacin iv

Seccin : 01
Clase del dia : Viernes 04/02/2012

Sueldo :

Enviar

Codigo HTML

<!-To change this template, choose Tools | Templates


and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<form name ="form1" method="POST" action="calcular_renta">
Sueldo :
<input type="text" name="sueldo" value =""/>
<input type="submit" value="Enviar" name="enviar" />
</form>
</body>
</html>
CODIGO SERVLET

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "calcular_renta", urlPatterns = {"/calcular_renta"})
public class calcular_renta extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
double sueldo =

Double.parseDouble(request.getParameter("sueldo"));
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet calcular_renta</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Sueldo : " + sueldo + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

You might also like