Commit ade207a4 by Cristian

inicial proyect

parent 461c21a4
...@@ -10,17 +10,21 @@ ...@@ -10,17 +10,21 @@
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head> </head>
<body class="container"> <body class="container">
<% ArrayList<Float>resultado=(ArrayList<Float>) request.getAttribute("resultado"); <%
ArrayList<Float> resultado= new ArrayList<Float>();
String tipo="";
String tipo =request.getAttribute("P0").toString(); if(request.getAttribute("array")!=null && request.getAttribute("P0")!=null){
if(tipo.toLowerCase().equals("c")){ resultado= (ArrayList<Float>) request.getAttribute("array");
tipo=" Celsius"; tipo =request.getAttribute("P0").toString();
}else if(tipo.toLowerCase().equals("f")){ if(tipo.toLowerCase().equals("c")){
tipo=" Fahrenheit"; tipo=" Celsius";
}else{ }else if(tipo.toLowerCase().equals("f")){
tipo=" Kelvin"; tipo=" Fahrenheit";
}else{
tipo=" Kelvin";
}
} }
%> %>
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"> crossorigin="anonymous">
</head> </head>
<body> <body class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Menu</a> <a class="navbar-brand" href="#">Menu</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
</li> </li>
</div> </div>
</nav> </nav>
</body class="container"> </body >
<%Exception resultado= null; <%String resultado= "";
if (request.getAttribute("resultado")!=null){ if (request.getAttribute("resultado")!=null){
resultado= (Exception) request.getAttribute("resultado"); resultado= (String) request.getAttribute("resultado");
} }
%> %>
<h1><%=resultado.toString() %></h1> <h1><%=resultado.toString() %></h1>
......
...@@ -41,40 +41,37 @@ public class ConversorServlet extends HttpServlet { ...@@ -41,40 +41,37 @@ public class ConversorServlet extends HttpServlet {
// TODO Auto-generated method stub // TODO Auto-generated method stub
doGet(request, response); doGet(request, response);
ArrayList<Float>resultado= new ArrayList<Float>(); ArrayList<Float>resultado= new ArrayList<Float>();
System.out.println("P1");
int error=0;
try { try {
if(request.getParameter("P1")!=null && request.getParameter("P0")!=null) { if(request.getParameter("P1")!=null && request.getParameter("P0")!=null) {
System.out.println(request.getParameter("P0").toString()); System.out.println(request.getParameter("P0").toString());
String p0= request.getParameter("P0").toString(); System.out.println(request.getParameter("P1").toString());
if(!"c".equals(p0)|| !"k".equals(p0)|| !"f".equals(p0)) { String p0=(String) request.getParameter("P0");
request.setAttribute("resultado", "valor de palo no esperado"); if(("C".equals(p0.toUpperCase())) || ("K".equals(p0.toUpperCase())) || ("F".equals(p0.toUpperCase()))) {
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) { }else {
rd.forward(request, response); error=1;
}
} }
resultado = convertidor(request.getParameter("P0").toString(),Float.parseFloat(request.getParameter("P1"))); resultado = convertidor(request.getParameter("P0").toString(),Float.parseFloat(request.getParameter("P1")));
System.out.println("aca llego"); System.out.println("aca llego");
request.setAttribute("P0", request.getParameter("P0")); request.setAttribute("P0", request.getParameter("P0"));
request.setAttribute("P1", request.getParameter("P1")); request.setAttribute("P1", request.getParameter("P1"));
request.setAttribute("resultado", resultado); request.setAttribute("array", resultado);
}else { }else {
request.setAttribute("resultado", "Parametros nulos");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp"); error=2;
if (rd != null) {
rd.forward(request, response);
}
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
System.out.println("exploto"); System.out.println("exploto");
request.setAttribute("resultado", "el valor no es numerico");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp"); error=3;
if (rd != null) {
rd.forward(request, response);
}
/*PrintWriter respuesta= response.getWriter(); /*PrintWriter respuesta= response.getWriter();
respuesta.println("<!DOCTYPE html>"); respuesta.println("<!DOCTYPE html>");
...@@ -91,10 +88,33 @@ public class ConversorServlet extends HttpServlet { ...@@ -91,10 +88,33 @@ public class ConversorServlet extends HttpServlet {
} }
finally { finally {
RequestDispatcher rd = request.getRequestDispatcher("/ConversorResultado.jsp");
if (rd != null) {
rd.forward(request, response); if(error==1) {
} request.setAttribute("resultado", "valor de palo no esperado");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
}else if(error==2){
request.setAttribute("resultado", "Parametros nulos");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
}else if(error==3){
request.setAttribute("resultado", "el valor no es numerico");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
}else {
RequestDispatcher rd = request.getRequestDispatcher("/ConversorResultado.jsp");
if (rd != null) {
rd.forward(request, response);
}
}
PrintWriter respuesta=response.getWriter(); PrintWriter respuesta=response.getWriter();
respuesta.println("<!DOCTYPE html>"); respuesta.println("<!DOCTYPE html>");
respuesta.print("<html>"); respuesta.print("<html>");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment