Commit 67e8785b by Cristian

inicila proyect

parent 122c52ea
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Agenda</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
</head>
<body class="container">
<br>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<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">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/index.html">Inicio <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/conversor.html">Conversor <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/agenda.html">Agenda<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/cartas.html">Cartas de Poker<span class="sr-only">(current)</span></a>
</li>
</div>
</nav>
<div >
<form action="guardar" method="POST">
<br>
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control" id="nombre" name="nombre" placeholder="Ej. Cristian" required>
</div>
<div class="form-group">
<label for="correo">Correo Electronico</label>
<input type="email" class="form-control" id="corro" name="correo_electronico" placeholder="Ej. snape727@gmail.com" required>
</div>
<div class="form-group">
<label for="telefono">Telefono</label>
<input type="text" class="form-control" id="telefono" name="telefono" placeholder="Ej. 0982160609" required>
</div>
<div class="form-group">
<label for="direccion">Direccin</label>
<input type="text" class="form-control" id="direccion" name="direccion" placeholder="Ejemplo Avda Mariscal Lopez" required>
</div>
<div class="d-flex">
<button type="submit" class="btn btn-dark btn-sm ml-auto ">Guardar</button>
</div>
</form>
</div>
</body>
<% if(request.getAttribute("resultado")!=null) {%>
<script>
alert("se creo correctamente")
</script>
<%};%>
</html>
\ No newline at end of file
......@@ -9,7 +9,7 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<body class="container">
<% ArrayList<Float>resultado=(ArrayList<Float>) request.getAttribute("resultado");
......@@ -23,7 +23,6 @@ if(tipo.toLowerCase().equals("c")){
}
%>
</body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Menu</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
......@@ -49,7 +48,7 @@ if(tipo.toLowerCase().equals("c")){
</nav>
<div class="container">
<div >
<br>
<div class="form-group row">
......@@ -83,4 +82,7 @@ if(tipo.toLowerCase().equals("c")){
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Error</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<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">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/index.html">Inicio <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/conversor.html">Conversor <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/agenda.html">Agenda<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/jweb-e002/cartas.html">Cartas de Poker<span class="sr-only">(current)</span></a>
</li>
</div>
</nav>
</body class="container">
<%Exception resultado= null;
if (request.getAttribute("resultado")!=null){
resultado= (Exception) request.getAttribute("resultado");
}
%>
<h1><%=resultado.toString() %></h1>
</html>
\ No newline at end of file
......@@ -8,7 +8,7 @@
<meta charset="ISO-8859-1">
<title>Resultado Carta</title>
</head>
<body>
<body class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Menu</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
......
......@@ -8,7 +8,7 @@
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
</head>
<body>
<body class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<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">
......@@ -31,5 +31,33 @@
</li>
</div>
</nav>
<div >
<form action="guardar" method="POST">
<br>
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control" id="nombre" name="nombre" placeholder="Ej. Cristian" required>
</div>
<div class="form-group">
<label for="correo">Correo Electronico</label>
<input type="email" class="form-control" id="corro" name="correo_electronico" placeholder="Ej. snape727@gmail.com" required>
</div>
<div class="form-group">
<label for="telefono">Telefono</label>
<input type="text" class="form-control" id="telefono" name="telefono" placeholder="Ej. 0982160609" required>
</div>
<div class="form-group">
<label for="direccion">Direccin</label>
<input type="text" class="form-control" id="direccion" name="direccion" placeholder="Ejemplo Avda Mariscal Lopez" required>
</div>
<div class="d-flex">
<button type="submit" class="btn btn-dark btn-sm ml-auto ">Guardar</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
......@@ -8,7 +8,7 @@
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
</head>
<body>
<body class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<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">
......@@ -31,27 +31,27 @@
</li>
</div>
</nav>
<div class="container">
<div >
<form action="dibujo_carta" method="GET">
<br>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Palo</label>
<label class="input-group-text" for="inputGroupSelect01">Palos posibles: S,C,H,D</label>
</div>
<select name="P0" required class="custom-select" id="P0" >
<select name="palo" required class="custom-select" id="palo" >
<option value="">Escoge...</option>
<option value="C">S</option>
<option value="F">C</option>
<option value="K">H</option>
<option value="K">D</option>
<option value="S">S</option>
<option value="C">C</option>
<option value="H">H</option>
<option value="D">D</option>
</select>
</div>
</div>
<div class="form-group">
<label for="tarea">Valor</label>
<input type="number" class="form-control" id="P1" name="P1" placeholder="Valor en Digitos" required minlength="1" maxlength="2" >
<label for="tarea">Valores posibles: A,2,3,4,5,6,7,8,9,T,J,Q,K</label>
<input type="text" class="form-control" required pattern="A|a|A|A|3|4|5|6|7|8|9|T|t|j|J|q|Q|K|k" title="Valores posibles: A,2,3,4,5,6,7,8,9,T,J,Q,K" id="valor" name="valor" placeholder="Valores posibles: A,2,3,4,5,6,7,8,9,T,J,Q,K" required maxlength="1" >
</div>
<div class="d-flex">
......
......@@ -8,7 +8,7 @@
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<body class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Menu</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
......@@ -33,7 +33,7 @@
</div>
</nav>
<div class="container">
<div >
<form action="ConversorServlet" method="POST">
<br>
<div class="form-group">
......
package servlet;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
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 AgendaServlet
*/
@WebServlet("/guardar")
public class AgendaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AgendaServlet() {
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 {
// TODO Auto-generated method stub
doGet(request, response);
int numeracionArchivo = 1;
String ruta;
File archivo;
BufferedWriter bw;
do {
ruta = getServletContext().getRealPath("/"+numeracionArchivo+".txt");
archivo = new File(ruta);
if(!archivo.exists()) {
System.out.println("Se crea el archivo "+numeracionArchivo+".txt");
break;
}
numeracionArchivo++;
}while(true);
archivo.createNewFile();
bw = new BufferedWriter(new FileWriter(archivo));
String nombre = request.getParameter("nombre");
String correoElectronico = request.getParameter("correo_electronico");
String telefono = request.getParameter("telefono");
String direccion = request.getParameter("direccion");
System.out.println(nombre);
System.out.println(correoElectronico);
System.out.println(telefono);
System.out.println(direccion);
bw.write(nombre+" "+"\n");
bw.write(correoElectronico+" "+"\n");
bw.write(telefono+" "+"\n");
bw.write(direccion+" "+"\n");
bw.close();
request.setAttribute("resultado", "correcto");
RequestDispatcher rd = request.getRequestDispatcher("/AgendaResultado.jsp");
if (rd != null) {
rd.forward(request, response);
}
}
}
......@@ -31,8 +31,8 @@ public class Carta extends HttpServlet {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
String palo = request.getParameter("P0").toUpperCase();
String valor = request.getParameter("P1").toUpperCase();
String palo = request.getParameter("palo").toUpperCase();
String valor = request.getParameter("valor").toUpperCase();
String rutaImagen = "imagenes/"+valor+palo+".png";
System.out.println(rutaImagen);
......
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
......@@ -39,28 +40,79 @@ public class ConversorServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
ArrayList<Float>resultado= new ArrayList<Float>();
System.out.println(request.getParameter("P0").toString());
System.out.println(Float.parseFloat(request.getParameter("P1")));
try {
ArrayList<Float>resultado = convertidor(request.getParameter("P0").toString(),Float.parseFloat(request.getParameter("P1")));
if(request.getParameter("P1")!=null && request.getParameter("P0")!=null) {
System.out.println(request.getParameter("P0").toString());
String p0= request.getParameter("P0").toString();
if(!"c".equals(p0)|| !"k".equals(p0)|| !"f".equals(p0)) {
request.setAttribute("resultado", "valor de palo no esperado");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
}
resultado = convertidor(request.getParameter("P0").toString(),Float.parseFloat(request.getParameter("P1")));
System.out.println("aca llego");
request.setAttribute("P0", request.getParameter("P0"));
request.setAttribute("P1", request.getParameter("P"));
request.setAttribute("P1", request.getParameter("P1"));
request.setAttribute("resultado", resultado);
}else {
request.setAttribute("resultado", "Parametros nulos");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("exploto");
request.setAttribute("resultado", "el valor no es numerico");
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
/*PrintWriter respuesta= response.getWriter();
RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
if (rd != null) {
rd.forward(request, response);
}
respuesta.println("<!DOCTYPE html>");
respuesta.print("<html>");
respuesta.println("<head>");
respuesta.println("<meta charset=\"UTF-8\">");
respuesta.println("<title>Convertidor!</title>");
respuesta.println("</head>");
respuesta.println("<body>");
respuesta.println("El valor introducido no es valido" );
respuesta.println("</body>");
respuesta.println("</html>");
return;*/
}
finally {
RequestDispatcher rd = request.getRequestDispatcher("/ConversorResultado.jsp");
if (rd != null) {
rd.forward(request, response);
}
PrintWriter respuesta=response.getWriter();
respuesta.println("<!DOCTYPE html>");
respuesta.print("<html>");
respuesta.println("<head>");
respuesta.println("<meta charset=\"UTF-8\">");
respuesta.println("<title>Convertidor!</title>");
respuesta.println("</head>");
respuesta.println("<body>");
respuesta.println("En grados Celsius: " + resultado.get(0) );
respuesta.println("<br>");
respuesta.println("En grados Fharenheit: " + resultado.get(1));
respuesta.println("<br>");
respuesta.println("En grados kelvin: " + resultado.get(2));
respuesta.println("</body>");
respuesta.println("</html>");
}
RequestDispatcher rd = request.getRequestDispatcher("/ConversorResultado.jsp");
if (rd != null) {
rd.forward(request, response);
}
}
......
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