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; /** * Servlet implementation class conversor_temperatura */ @WebServlet("/conversor_temperatura") public class conversor_temperatura extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public conversor_temperatura() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter escribir = response.getWriter(); try { double fahrenheit; double celsius; double kelvin; double entrada = Double.parseDouble(request.getParameter("P1")); double selector = Double.parseDouble(request.getParameter("P0")); if(selector == 0) { //Esto es si la temperatura esta en celsius celsius = entrada; fahrenheit = (entrada * 9/5) + 32; kelvin = entrada + 273.15; escribir.append( "\n" + "\n" + "
\n" + " \n" + "Celsius: "+celsius+"
\n" + "Fahrenheit: "+fahrenheit+"
\n" + "Kelvin: "+kelvin+"
Celsius: "+celsius+"
\n" + "Fahrenheit: "+fahrenheit+"
\n" + "Kelvin: "+kelvin+"
Celsius: "+celsius+"
\n" + "Fahrenheit: "+fahrenheit+"
\n" + "Kelvin: "+kelvin+"
La entrada solo admite numeros
\n" + "Volver al conversor de temperaturas