Commit 135e4b1a by Matias Ferreira

tarea terminada

parent bc5804a6
Manifest-Version: 1.0
Class-Path:
<!DOCTYPE html>
<html>
<head>
<title>Tarea JWeb</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p>hola mundos</p>
<ol>
<li><a href="http://localhost:8080/WebProjectTest/tabla-multiplicar">aprende a multiplicar!</a></li>
<li><a href="http://localhost:8080/WebProjectTest/factorial">aprende a factorializar!</a></li>
<li><a href="http://localhost:8080/WebProjectTest/show-me-the-bits">aprender conversion decimal/binario!</a></li>
</ol>
</body>
</html>
\ No newline at end of file
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/factorial")
public class FactorialRequestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// req -> datos que envia el navegador al servidor de aplicaciones
// resp -> la respuesta que envia el servidor de aplicaciones al navegador
PrintWriter pw = new PrintWriter(resp.getOutputStream());
// String s1 = req.getParameter("s1");
// String s2 = req.getParameter("s2");
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos factorializador</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un factorializador</h1>"
+ "<div>"
+ "<form action=\"factorial-response\" >"
+ "Introduzca el numero: <input type=\"text\" name=number><br>"
+ "<input type=\"submit\">"
+ "</form>"
+ "</div>"
+ "</body>"
+ "</html>");
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/factorial-response")
public class FactorialResponseServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
Boolean valido=true;
String parametro = req.getParameter("number");
if(parametro.length() <1)
valido=false;
for(int i = 0 ; i < parametro.length(); i++) {
if( ( !Character.isDigit(parametro.charAt(i)) && i > 0) && !(Character.isDigit(parametro.charAt(i)) && i == 0 && parametro.charAt(i) != '-' ) ) {
valido=false;
break;
}
}
if (!valido) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "No se puede generarla tabla de multiplicar. Valor del parametro \" " + parametro + " \" invalido."
+ "</body>"
+ "</html>");
}
else {
Integer numero = Integer.parseInt(parametro);
if(numero > 100) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "Mi programa solo conoce el factorial de hasta el numero 100. El numero pasado fue: "+numero
+ "</body>"
+ "</html>");
}
else if(numero<0) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "Mi programa no sabe obtener el factorial de numeros negativos"
+ "</body>"
+ "</html>");
}
else{
long facto=1;
for (long i = 2; i <=numero;i++)
facto*=i;
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al factorializador</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un generador de factorial de numeros</h1>"
+ "<div>"
+ "<p>El factorial de "+ numero+" es: " + facto +"</p>"
+ "</div>"
+ "</body>"
+ "</html>");
}
}
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/show-me-the-bits")
public class ShowMeTheBitsRequestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al show me the bits</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un conversor sistemas de numeracion</h1>"
+ "<div>"
+ "<form action=\"show-me-the-bits-response\" >"
+ "Introduzca el numero: <input type=\"text\" name=number><br>"
+ "<input type=\"submit\">"
+ "</form>"
+ "</div>"
+ "</body>"
+ "</html>");
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/show-me-the-bits-response")
public class ShowMeTheBitsResponseServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
Boolean valido=true;
String parametro = req.getParameter("number");
Integer [] vectorResultado = new Integer [16];
String tipo="";
if(parametro.length() < 1)
valido=false;
else if(parametro.length() >1 ) {
if(parametro.charAt(0) == '0') {
if(parametro.charAt(1) == 'x')
tipo = "hexadecimal";
else
tipo = "octal";;
}else
tipo="decimal";
}else
tipo= "decimal";;
if(tipo.equals("decimal")) {
for ( int i = 0 ; i< parametro.length(); i++)
if(!Character.isDigit(parametro.charAt(i)))
valido = false;
}
else if(tipo.equals("octal")) {
for ( int i = 1 ; i< parametro.length(); i++)
if(!Character.isDigit(parametro.charAt(i)))
valido = false;
}
else if(tipo.equals("hexadecimal")) {
for ( int i = 2 ; i < parametro.length(); i++ )
if( !isHexaDigit(parametro.charAt(i) ) )
valido = false;
}
int validAux = 0;
if(valido) {
if(tipo.equals("decimal") )
validAux = Integer.parseInt(parametro,10);
else if( tipo.equals("hexadecimal") )
validAux = Integer.parseInt(parametro.substring(2),16);
else
validAux = Integer.parseInt(parametro.substring(1),8);
}
if(validAux > 65535)
valido = false;
if (!valido) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "No se puede generarla tabla de multiplicar. Valor del parametro \"" + parametro + "\" invalido."
+ "</body>"
+ "</html>");
}
else {
transformacion(tipo, parametro, vectorResultado);
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al conversor de numeros</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un conversor de sistemas de numeracion</h1>"
+ "<table>"
+ "<tr>");
for(int i = 15; i >= 0 ; i--) {
if(vectorResultado[i] == 1) {
pw.write("<th style=\"color: gold ; background-color:darkblue;\">" + vectorResultado[i]+"</th>");
}
else {
pw.write("<th style=\"color:fuchsia ; background-color:darkblue;\">"+vectorResultado[i]+"</th>");
}
if(i == 8) {
pw.write("<th> === </th>");
}
else if(i == 0) {
pw.write("</tr>");
}
else
pw.write("<th> | </th>");
}
pw.write( "</table>"
+ "</body>"
+ "</html>");
}
pw.close();
}
public void transformacion(String tipo, String valor, Integer [] resultado) {
if(tipo.equals("decimal")) {
Integer numero = Integer.parseInt(valor);
int [] vectorAux = new int[16];
vectorAux[0] = 1;
for(int i = 1 ; i < 16 ;i++) {
vectorAux[i] = vectorAux[i-1]*2;
}
for(int i = 15 ; i > -1 ; i--) {
if(numero >= vectorAux[i]) {
resultado[i]=1;
numero%=vectorAux[i];
}
else {
resultado[i] = 0;
}
}
}
else if(tipo.equals("hexadecimal") ) {
String cadenaAux = "";
int k = 0;
for (int i = valor.length()-1 ; i > 1 ; i--){
cadenaAux = hexaToBin(valor.charAt(i));
for(int j = 3 ; j > -1 ; j--) {
resultado[k++]=Integer.parseInt(""+cadenaAux.charAt(j));
}
}
while(k<16)
resultado[k++]=0;
}
else if( tipo.equals("octal") ) {
String cadenaAux = "";
int k = 0;
for (int i = valor.length()-1 ; i > 0 ; i--){
cadenaAux = octalToBin(valor.charAt(i));
for(int j = 2 ; j > -1; j--) {
resultado[k++]=Integer.parseInt(""+cadenaAux.charAt(j));
}
}
while(k<16)
resultado[k++]=0;
}
}
public String hexaToBin(char caracter) {
if(caracter == 'F')
return "1111";
if(caracter == 'E')
return "1110";
if(caracter == 'D')
return "1101";
if(caracter == 'C')
return "1100";
if(caracter == 'B')
return "1011";
if(caracter == 'A')
return "1010";
if(caracter == '9')
return "1001";
if(caracter == '8')
return "1000";
if(caracter == '7')
return "0111";
if(caracter == '6')
return "0110";
if(caracter == '5')
return "0101";
if(caracter == '4')
return "0100";
if(caracter == '3')
return "0011";
if(caracter == '2')
return "0010";
if(caracter == '1')
return "0001";
if(caracter == '0')
return "0000";
return "";
}
public String octalToBin(char caracter) {
if(caracter == '7')
return "111";
if(caracter == '6')
return "110";
if(caracter == '5')
return "101";
if(caracter == '4')
return "100";
if(caracter == '3')
return "011";
if(caracter == '2')
return "010";
if(caracter == '1')
return "001";
if(caracter == '0')
return "000";
return "";
}
public Boolean isHexaDigit(char caracter) {
if( caracter == '0' ||caracter == '1' ||caracter == '2' ||caracter == '3' ||
caracter == '4' ||caracter == '5' ||caracter == '6' ||caracter == '7' ||
caracter == '8' ||caracter == '9' ||caracter == 'A' ||caracter == 'B' ||
caracter == 'C' ||caracter == 'D' ||caracter == 'E' ||caracter == 'F' ) {
return true;
}
else
return false;
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/suma")
public class SumaRequestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al sumador</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un sumador</h1>"
+ "<div>"
+ "<form action=\"suma-response\">"
+ "Enter 1st number: <input type=\"text\" name=s1><br>"
+ "Enter 2nd number: <input type=\"text\" name=s2><br>"
+ "<input type=\"submit\">"
+ "</form>"
+ "</div>"
+ "</body>"
+ "</html>");
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/suma-response")
public class SumaResponseServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
String s1 = req.getParameter("s1");
String s2 = req.getParameter("s2");
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al sumador</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un sumador</h1>"
+ "<div>"
+ "<p>Operador s1: " + s1 + "</p>"
+ "<p>Operador s2: " + s2 + "</p>"
+ "<p>s1 + s2: " + (Double.parseDouble(s1) + Double.parseDouble(s2)) + "</p>"
+ "</div>"
+ "</body>"
+ "</html>");
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/tabla-multiplicar")
public class TablaMultiplicarRequestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
pw.write("<html>"
+ "<head>"
+ "<title>Hola, Aqui te enseño las tablas de la multiplicacion</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un generador de tablas de multiplicar</h1>"
+ "<div>"
+ "<form action=\"tabla-multiplicar-response\">"
+ "Enter 1st number: <input type=\"text\" name=number><br>"
+ "<input type=\"submit\">"
+ "</form>"
+ "</div>"
+ "</body>"
+ "</html>");
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/tabla-multiplicar-response")
public class TablaMultiplicarResponseServelet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
PrintWriter pw = new PrintWriter(resp.getOutputStream());
Boolean valido=true;
String parametro = req.getParameter("number");
if(parametro.length() <1)
valido=false;
for(int i = 0 ; i < parametro.length(); i++) {
if( ( !Character.isDigit(parametro.charAt(i)) && i > 0) && !(Character.isDigit(parametro.charAt(i)) && i == 0 && parametro.charAt(i) != '-' ) ) {
valido=false;
break;
}
}
if (!valido) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "No se puede generarla tabla de multiplicar. Valor del parametro \"" + parametro + "\" invalido."
+ "</body>"
+ "</html>");
}
else {
Integer numero = Integer.parseInt(parametro);
if(numero > 100) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "Mi programa solo conoce la tabla de multiplicar hasta el numero 100. El numero pasado fue: "+numero
+ "</body>"
+ "</html>");
}
else if(numero<0) {
pw.write("<html>"
+ "<head>"
+ "<title>Error de parametro</title>"
+ "</head>"
+ "<body>"
+ "Mi programa no sabe las tablas de multiplicar de numeros negativos"
+ "</body>"
+ "</html>");
}
else{
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos al multiplicador</title>"
+ "</head>"
+ "<body>"
+ "<h1>Soy un generador de tablas de multiplicar</h1>"
+ "<table style=\"width:5%\">"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>1 </th>" +"<th>=</th>" + "<th>"+(numero*1) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>2 </th>" +"<th>=</th>" + "<th>"+(numero*2) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>3 </th>" +"<th>=</th>" + "<th>"+(numero*3) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>4 </th>" +"<th>=</th>" + "<th>"+(numero*4) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>5 </th>" +"<th>=</th>" + "<th>"+(numero*5) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>6 </th>" +"<th>=</th>" + "<th>"+(numero*6) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>7 </th>" +"<th>=</th>" + "<th>"+(numero*7) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>8 </th>" +"<th>=</th>" + "<th>"+(numero*8) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>9 </th>" +"<th>=</th>" + "<th>"+(numero*9) + "</th>" + "</tr>"
+ "<tr>"+ "<th>"+numero+"</th>" + "<th>*</th>"+ "<th>10</th>" +"<th>=</th>" + "<th>"+(numero*10)+ "</th>" + "</tr>"
+ "</tdr>"
+ "</body>"
+ "</html>");
}
}
pw.close();
}
}
package com.roshka.webprojecttest.servlets;
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;
@WebServlet("/test1")
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// req -> datos que envia el navegador al servidor de aplicaciones
// resp -> la respuesta que envia el servidor de aplicaciones al navegador
PrintWriter pw = new PrintWriter(resp.getOutputStream());
pw.write("<html>"
+ "<head>"
+ "<title>Hola, bienvenidos</title>"
+ "</head>"
+ "<body>"
+ "Hola, estoy dentro del HTML"
+ "</body>"
+ "</html>");
pw.close();
}
}
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