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" + " Resultado temperaturas\n" + " \n" + "\n" + "

Los resultados son

\n" + "

Celsius: "+celsius+"

\n" + "

Fahrenheit: "+fahrenheit+"

\n" + "

Kelvin: "+kelvin+"



\n" + "Volver al conversor de temperaturas

" + "Volver al menu principal

" + "\n" + "" ); }else if(selector == 1) { //Esto es si la temperatura esta en fahrenheit celsius = (entrada - 32) * 5/9; fahrenheit = entrada; kelvin =((entrada - 32)*5/9) + 273.15; escribir.append( "\n" + "\n" + "\n" + " \n" + " Resultado temperaturas\n" + " \n" + "\n" + "

Los resultados son

\n" + "

Celsius: "+celsius+"

\n" + "

Fahrenheit: "+fahrenheit+"

\n" + "

Kelvin: "+kelvin+"



\n" + "Volver al conversor de temperaturas

" + "Volver al menu principal

" + "\n" + "" ); }else if(selector == 2) { //Esto es si la temperatura esta en kelvin celsius = entrada - 273.15; fahrenheit = ((entrada - 273.15)*9/5)+32; kelvin =entrada; escribir.append( "\n" + "\n" + "\n" + " \n" + " Resultado temperaturas\n" + " \n" + "\n" + "

Los resultados son:

\n" + "

Celsius: "+celsius+"

\n" + "

Fahrenheit: "+fahrenheit+"

\n" + "

Kelvin: "+kelvin+"



\n" + "Volver al conversor de temperaturas

" + "Volver al menu principal

" + "\n" + "" ); } }catch(Exception e) { escribir.append( "\n" + "\n" + "\n" + " \n" + " Resultado temperaturas\n" + " \n" + "\n" + "

Los resultados son:

\n" + "

La entrada solo admite numeros

\n" + "Volver al conversor de temperaturas

" + "Volver al menu principal

" + "\n" + "" ); } } }