JavaDabbaDoo.org -Tu comunidad Java parlante Implementar MVC - Struts 1.2
Inicio | Cursos infosintesis.net liberados | Java EE | Registrar a un usuario en un sitio Web con Struts 1.2
Registrar a un usuario en un sitio Web con Struts 1.2
Paso 2: Operativa

Controlador - RegistroAction - Crear el esqueleto de un Action

Las subclases de la Clase Action se ejecutan en respuesta a una petición de un usuario.

Las subclases de Action desempeñan el papel de

Ahora vamos a crear una subclase de Action llamada RegistroAction. Para ello en la ventana properties vamos a hacer clic con el botón derecho sobre nuestro proyecto de ejemplo llamado proregusuariostruts y seleccionamos Other...

Entonces elegimos Struts | Struts Action

NetBeans 6 - Crear una subclase de Action - Struts | Struts Action

En el cuadro de diálogo New Struts Action escribimos los siguientes datos

NetBeans 6 - Crear una subclase de Action - New Struts Action | Name and Location | Class Name: RegistroAction | Package: paqactions | Action Path: /registro

Hacemos clic sobre el botón Next y en el nuevo cuadro de diálogo New Struts Action escribimos los siguientes datos

NetBeans 6 - Crear una subclase de Action - New Struts Action | ActionForm Bean, Parameter | Use ActionForm Bean | ActionForm Bean Name: RegistroActionForm | Input Resource: /registroForm.jsp

Para salir de este cuadro de diálogo hacemos clic sobre el botón Finish.

Como podemos observar, en el fichero struts-config.xml, el asistente de NetBeans ha añadido el elemento <action>

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
 <form-beans>
  <form-bean name="RegistroActionForm" type="paqactionforms.RegistroActionForm"/>
 </form-beans>

 <global-exceptions>

 </global-exceptions>

 <global-forwards>
  <forward name="welcome" path="/Welcome.do"/>
 </global-forwards>

 <action-mappings>
  <action input="/registroForm.jsp" name="RegistroActionForm" path="/registro" 
   scope=
"session" type="paqactions.RegistroAction"/>
  <action path="/Welcome" forward="/welcomeStruts.jsp"/>
 </action-mappings>

 <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

 <message-resources parameter="literales/ApplicationResource"/>

 <plug-in className="org.apache.struts.tiles.TilesPlugin" >
  <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
  <set-property property="moduleAware" value="true" />
 </plug-in>

 <!-- ================= Validator plugin ========================= -->
 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
  <set-property
   property="pathnames"
   value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
 </plug-in>

</struts-config>

Y también ha creado el esqueleto de la Clase RegistroAction

package paqactions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class RegistroAction extends org.apache.struts.action.Action {

 /* forward name="success" path="" */
 private final static String SUCCESS = "success";


 public ActionForward execute(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request, HttpServletResponse response)
                          throws Exception {

  return mapping.findForward(SUCCESS);
 }
}

Página anterior
Ignasi Pérez Valls
Infosintesis Solutions Group


Junio 2009
JavaDabbaDoo.org
Tu comunidad Java parlante. Cursos abiertos, tutoriales y mucho mucho más ...