dibujo_carta.java 3.75 KB
Newer Older
roshka committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112


import java.io.File;
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 dibujo_carta
 */
@WebServlet("/dibujo_carta")
public class dibujo_carta extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public dibujo_carta() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter escribirPagina = response.getWriter();
		try {
			String palo = request.getParameter("P0");
			int valor = Integer.parseInt(request.getParameter("P1"));
			palo = palo.toUpperCase();
			if(palo.compareTo("S")==0 || palo.compareTo("H")==0 || palo.compareTo("C")==0 || palo.compareTo("D")==0) {
				if(valor>=1 && valor<=13) {
					escribirPagina.append(
							"<!DOCTYPE html>\n" + 
							"<html>\n" + 
							"<head>\n" + 
							"<meta charset=\"UTF-8\">\n" + 
							"<title>Agenda</title>\n" + 
							"</head>\n" + 
							"<body>\n" + 
							"	<h1>Tu carta es: </h1>\n" + 
							"	<img src=\"cartas/"+ valor + palo + ".png"+"\" alt=\"Resultado carta\" width=\"227\" height=\"315\"><br><br>\n" +
							"	<a href=\"http://localhost:8080/_jweb-e001/cartas.html\">Volver al selector de carta</a><br><br>" +
							"	<a href=\"http://localhost:8080/_jweb-e001/index.html\">Volver al menu principal</a>" + 
							"</body>\n" + 
							"</html>"
					);
				}else {
					escribirPagina.append(
							"<!DOCTYPE html>\n" + 
							"<html>\n" + 
							"<head>\n" + 
							"<meta charset=\"UTF-8\">\n" + 
							"<title>Agenda</title>\n" + 
							"</head>\n" + 
							"<body>\n" + 
							"	<p>El campo valor solo admite valores entre entre el 1 y el 13</p><br><br>\n" + 
							"	<a href=\"http://localhost:8080/_jweb-e001/cartas.html\">Volver al selector de carta</a><br><br>\n" +
							"	<a href=\"http://localhost:8080/_jweb-e001/index.html\">Volver al menu principal</a>" +
							"</body>\n" + 
							"</html>"
							);
				}
			}else {
				escribirPagina.append(
						"<!DOCTYPE html>\n" + 
						"<html>\n" + 
						"<head>\n" + 
						"<meta charset=\"UTF-8\">\n" + 
						"<title>Agenda</title>\n" + 
						"</head>\n" + 
						"<body>\n" + 
						"	<p>El campo del palo solo admite valores:<br>* S<br>* H<br>* C<br>* D</p><br><br>\n" + 
						"	<a href=\"http://localhost:8080/_jweb-e001/cartas.html\">Volver al selector de carta</a><br><br>\n" +
						"	<a href=\"http://localhost:8080/_jweb-e001/index.html\">Volver al menu principal</a>" +
						"</body>\n" + 
						"</html>"
						);
			}
		}catch(NumberFormatException e){
			escribirPagina.append(
					"<!DOCTYPE html>\n" + 
						"<html>\n" + 
						"<head>\n" + 
						"<meta charset=\"UTF-8\">\n" + 
						"<title>Agenda</title>\n" + 
						"</head>\n" + 
						"<body>\n" + 
						"	<p>El campo del valor solo admite numeros enteros</p><br><br>\n" + 
						"	<a href=\"http://localhost:8080/_jweb-e001/cartas.html\">Volver al selector de carta</a><br><br>" +
						"	<a href=\"http://localhost:8080/_jweb-e001/index.html\">Volver al menu principal</a>" +
						"</body>\n" + 
						"</html>"
					);
		}
	}

	/**
	 * @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);
	}

}