Comenzamos creando nuestra Aplicación Web en Netbeans.
- File, new project, Java Web y Web Application.
- Luego damos clic en NEXT.
- y en Project name escribimos el nombre de nuestro primer proyecto, en este caso lo llamaremos: Encuesta.
- Después de haber hecho lo anterior, creamos un nuevo "jsp" procesar. Para ello damos clic derecho sobre Web pages, new, JSP y en File Name escribimos "procesar" y por último damos clic en Finish.
- Una vez hecho todos los pasos anteriores, comenzamos con la Codificación!!
Para index.jsp escribiremos lo siguiente:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="procesar.jsp" method="POST">
<center>
<table border="1">
<tr>
<td> ENCUESTA</td>
<td></td>
</tr>
<tr>
<td> Qué frutas prefiere más?</td>
</tr>
<td>
<input type="checkbox" name="respuesta" value="Manzana" />MANZANA
<input type="checkbox" name="respuesta" value="Fresa" />FRESA
<input type="checkbox" name="respuesta" value="Mango" />MANGO
</td>
<tr>
<td colspan="2" aling="center"> <input type="submit" value="enviar" /> </td>
</tr>
</table>
</center>
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="procesar.jsp" method="POST">
<center>
<table border="1">
<tr>
<td> ENCUESTA</td>
<td></td>
</tr>
<tr>
<td> Qué frutas prefiere más?</td>
</tr>
<td>
<input type="checkbox" name="respuesta" value="Manzana" />MANZANA
<input type="checkbox" name="respuesta" value="Fresa" />FRESA
<input type="checkbox" name="respuesta" value="Mango" />MANGO
</td>
<tr>
<td colspan="2" aling="center"> <input type="submit" value="enviar" /> </td>
</tr>
</table>
</center>
</form>
</body>
</html>
Para procesar.jsp escribiremos lo siguiente:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>SUS RESPUESTAS FUERON</h1>
<%
String [] valores= request.getParameterValues("respuesta");
if (valores != null)
{ for (int i=0;i<valores.length;i++){
out.println(valores[i]+"<br>");}
}else{
out.println("ud. no escogio ningun items");
}
%>
</body>
</html>
- Una vez terminado la codificación, ejecutaremos la aplicación y obtendremos como resultado lo siguiente:




Comentarios
Publicar un comentario