Você está na página 1de 3

Index

<%--
Document : index
Created on : 15/08/2017, 08:44:05 AM
Author : Estudiante_PC
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Informacion</title> <!Titulo de la pagina web>
</head>
<body>

<form action="informacion.jsp" method="get"><!se crean los espacios para


ingresar el nombre y la edad>
<input type="text" name="nombre"/>
<input type="text" name="edad"/>
<input type="submit" value="Mandar Informacion"/>
</form>

</body>
</html>
-----------------------------------------------------------------------------------
---------------
Informacion

<%--
Document : infromacion
Created on : 15/08/2017, 09:41:33 AM
Author : Estudiante_PC
--%>

<%@page import="modelo.Persona"%><!Importar la clase modelo>


<%@page contentType="text/html" pageEncoding="UTF-8"%><!creacion de la pagina en
HTML "UTF-8" Es para decir que es en espaol>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Informacion</title>
</head>
<body>
<%
try{ // Se ejecuta algo que puede producir una excepcin
Persona persona = new Persona();
persona.setNombre(request.getParameter("nombre"));
persona.setEdad(Integer.valueOf(request.getParameter("edad")));
out.println("Mi nombre es : " + persona.getNombre() + ", Mi edad es :
" + persona.getEdad());

}catch(NumberFormatException ex){
out.print("<script type=text/javascript>");//Envia mensaje de error
al no ingresar numeros en la casilla edad
out.print("alert('Formato incorrecto');");
out.print("location.href='index.jsp';");
out.print("</script>");

}catch(Exception e){// manejo de una excepcin cualquiera


out.print("<script type=text/javascript>");//Envia mensaje de error
al no ingresar letras en la casilla nombre
out.print("alert('Error de mensaje');");
out.print("location.href='index.jsp';");
out.print("</script>");
}
%>
</body>
</html>
-----------------------------------------------------------------------------------
---------------

Persona

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package modelo;

/**
*
* @author Estudiante_PC
*/
public class Persona {

private String nombre;


private int edad;

public Persona() {
nombre = " ";//variable nombre,vacia para poder ingresar cualquier dato
edad = 0;
}

/**
* @return the nombre
*/
public String getNombre() {//encapsulamos nombre y edad
return nombre;
}

/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}

/**
* @return the edad
*/
public int getEdad() {
return edad;
}

/**
* @param edad the edad to set
*/
public void setEdad(int edad) {
this.edad = edad;
}
}

Você também pode gostar