Commit 6d414b25 by roshka

Primer ejercicio de Java Web

parents
Instrucciones para poder utilizar la agenda es entrando en la carpeta poker(no ingrese en la carpeta agenda porque era de prueba) y al crear un registro utilice la flecha para volver ya que en el momento de crear el archivo cerrar el programa, el primer archivo se elimina. Luego el resto su uso es normal.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-openjdk-amd64">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0 ">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Poker</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="Poker">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="Poker"/>
<property name="java-output-path" value="/Poker/build/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v8.0 "/>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Manifest-Version: 1.0
Class-Path:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Agenda</title>
</head>
<body>
<h1>Agenda</h1>
<form action="/Poker/agenda" method="post">
Nombre <input type="text" name="nombre">
E-mail <input type="text" name="correo_electronico">
Telefono <input type="text" name="telefono">
Direccion <input type="text" name="direccion">
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cartas</title>
</head>
<body>
<h1>Cartas</h1>
<form action="/Poker/carta" method="post">
<select name="palo">
<option value="S">Spade</option>
<option value="H">Hearts</option>
<option value="C">Clubs</option>
<option value="D">Diamonds</option>
</select>
Numero de Carta<input type="text" name="valor">
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Convertidor</title>
</head>
<body>
<h1>Convertidor de Temperatura</h1>
<form action="/Poker/conversor" method="post">
<select name="tipo_temperatura">
<option value="celcius">C</option>
<option value="fahrenheit">F</option>
<option value="kelvin">K</option>
</select>
<input type="text" name="valor_temperatura">
<input type="submit"/>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Menu Principal</title>
</head>
<body>
<h1>Menu Principal</h1>
<br>
<ol>
<li type="circle"><a href="Pagina/conversor.html">Convertir Temperatura</a></li>
<li type="circle"><a href="Pagina/agenda.html">Agenda</a></li>
<li type="circle"><a href="Pagina/cartas.html">Poker Cartas</a></li>
</ol>
</body>
</html>
\ No newline at end of file
package com.roshka.bootcamp004;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
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 Agenda
*/
@WebServlet("/agenda")
public class Agenda extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Agenda() {
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());
response.getWriter().println("hola");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("nombre");
String correo = request.getParameter("correo_electronico");
String tel = request.getParameter("telefono");
String dir = request.getParameter("direccion");
int contador = 1;
String ruta;
File archivo;
BufferedWriter bw;
do {
ruta = this.getServletContext().getRealPath("/Pagina/archivo"+contador+".txt");
archivo = new File(ruta);
contador++;
} while (archivo.exists());
System.out.println(archivo.getAbsolutePath());
archivo.createNewFile();
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(name);
bw.write(correo);
bw.write(tel);
bw.write(dir);
bw.close();
response.getWriter().println("<html>\n" +
"<head>\n" +
"<meta charset=\"UTF-8\">"
+ "<title>Agenda</title>\n" +
"</head>\n" +
"<body>"
+ "Nombre: "+name+"<br>"
+ "Correo: "+correo+"<br>"
+ "Telefono: "+tel+"<br>"
+ "Direccion: "+dir+"<br>"
+ "Archivo Nro: "+contador+"."
+ "</body>"
+ "</html>"
);
}
}
package com.roshka.bootcamp004;
import java.io.IOException;
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
*/
@WebServlet("/conversor")
public class Conversor extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Conversor() {
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());
response.getWriter().println("hola");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String tipo = request.getParameter("tipo_temperatura");
String valor = request.getParameter("valor_temperatura");
double valor_temperaturaD = Double.parseDouble(valor);
double kel = 0;
double fah = 0;
double cel = 0;
if (tipo.equals ("kelvin")) {
kel = valor_temperaturaD;
fah = fah + (valor_temperaturaD - 273.15) * 9/5 + 32;
cel = cel + (valor_temperaturaD - 273.15);
}
if (tipo.equals("fahrenheit")) {
fah = valor_temperaturaD;
kel = kel + ((valor_temperaturaD - 32) * 5/9 + 273.15);
cel = cel + ((valor_temperaturaD - 32) * 5/9);
}
if (tipo.equals("celcius")) {
cel = valor_temperaturaD;
kel = kel + (valor_temperaturaD + 273.15);
fah = fah + ((valor_temperaturaD * 9/5) + 32 );
}
response.getWriter().println("<html>\n" +
"<head>\n" +
"<meta charset=\"UTF-8\">"
+ "<title>Convertidor</title>\n" +
"</head>\n" +
"<body>"
+ "La temperatura es en: <br>"
+ "Kelvin: "+kel+ " grados <br>"
+ "Fahrenheit "+fah+ " grados <br>"
+ "Celcius "+cel+ " grados <br>"
+ "</body>"
+ "</html>"
);
}
}
package com.roshka.bootcamp004;
import java.io.IOException;
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 Poker
*/
@WebServlet("/carta")
public class carta extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public carta() {
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 {
String palo = request.getParameter("palo");
String valor = request.getParameter("valor");
String ruta = "PNG/"+valor+palo+".png";
response.getWriter().println("<html>\n" +
"<head>\n" +
"<meta charset=\"UTF-8\">"
+ "<title>Cartas</title>\n" +
"</head>\n"
+"<img src=\""+ruta+"\">"
+ "</body>"
+ "</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