You are on page 1of 13

Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Struts es un framework de cdigo abierto que se extiende de la API Java Servlet y utiliza
un Modelo, Vista, Controlador (MVC) el cual permite crear mantenibles, extensible y aplicaciones
web flexibles basados en tecnologas estndar, como las pginas JSP, JavaBeans, paquetes de
recursos, y XML.

Comenzamos abriendo un Nuevo proyecto Java Web.

Lo nombramos MyStrutsApp
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

En Frameworks elegimos la opcin Struts

Podemos verificar, en la vista lgica los archivos agregados.


Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Web.xml

Ahora creamos el archivo jsp. Clic Izquierdo en MystrutApp New JSP Lo nombramos como
login.jsp
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Ahora agregamos una tabla, Menu Window Palette

La cual definimos de la siguiente manera:

AL dar OK, podemos ver login.jsp de la siguiente forma:


Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Ahora modificamos, para que se muestre lo siguiente:


Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Despus creamos el archivo sucess.jsp, el cual modificamos como se muestra a continuacin:

Creamos un ActionForm Bean, Clic derecho en el Proyecto, New Others. Elegimos la opcin
Struts Struts ActionForm Bean.
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Lo nombramos como LoginForm

Como se puede ver el IDE proporciona soporte de navegacin el struts-config.xml

En el ActionForm Bean creamos campos, Clic derecho en email Getter and Setter
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Elegimos email : String y damos clic en Generate.

Ahora generamos una clase Action. Clic derecho en el Proyecto, New Others. Elegimos la opcin
Struts Struts Action. Y la nombramos como LoginAction.
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Configuramos el Action de la siguiente forma:

Y observamos en struts-config.xml la entrada de Action.

En LoginAction observamos el mtodo execute:

Para acceder a los datos del Bean y preparar el estado de Desvo, debemos modificar el
LoginAction de la siguiente manera:
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Ahora configuramos el mensaje de error, para informar al usuario que la validacin ha fallado.
Modificamos en LoginForm de la siguiente forma:

Tambin se hacen cambios en login.jsp


Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Entonces, ya completa LoginAction debe quedar como se muestra a continuacin:

Para que funcione correctamente y coincidad los jsp se deben aadir forward. En struts-config.xml
Clic derecho Struts Add Forward

Agregamos sucess y buscamos su ubicacin, el cuadro de dilogo debe quedar de la siguiente


manera:
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

Y el resultado es el siguiente:
Introduction to the Struts Web Framework 8CM1 Arreguin Prez Jenny

You might also like