Hola, estoy haciendo un proyecto que tiene un login y un formulario de registro.
El login tiene un vinculo hacia el registro.
Puedo imprimir los datos ingresados en el login.
Pero no puedo imprimir los datos ingresados en el registro.
LoginAction
Código:
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends org.apache.struts.action.Action {
private static final String SUCCESS = "success";
private static final String FAILURE = "failure";
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginActionForm data = (LoginActionForm)form;
String email = data.getEmail();
String pass = data.getPass();
if ((email.equals("[email protected]")) && (pass.equals("admin"))){
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
}
}
}
LoginActionForm
Código:
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class LoginActionForm extends org.apache.struts.action.ActionForm {
private String email;
private String pass;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public LoginActionForm() {
super();
// TODO Auto-generated constructor stub
}
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getEmail() == null || getEmail().length() < 6) {
errors.add("wrongemail", new ActionMessage("errors.email", "This e-mail"));
}
if (getPass() == null || getPass().length() < 5) {
errors.add("wrongpass", new ActionMessage("errors.minlength", "Password", "6"));
}
return errors;
}
}
RegistroAction
Código:
/*
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class RegistroAction extends org.apache.struts.action.Action {
private static final String SUCCESS = "success";
private static final String FAILURE = "failure";
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
RegistroActionForm data = (RegistroActionForm)form;
String email = data.getEmail();
String pass = data.getPass();
if ((email.equals("[email protected]")) && (pass.equals("admin"))){
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
}
}
}
RegistroActionForm
Código:
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class RegistroActionForm extends org.apache.struts.action.ActionForm {
private String name;
private int number;
private String email;
private String pass;
private String nombre;
public String getNombre() {
return nombre;
}
public void setNombre(String string) {
nombre = string;
}
public String getPass() {
return pass;
}
public void setPass(String string) {
pass = string;
}
public String getEmail() {
return email;
}
/**
* @param string
*/
public void setEmail(String string) {
email = string;
}
public String getName() {
return name;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
/**
* @return
*/
public int getNumber() {
return number;
}
/**
* @param i
*/
public void setNumber(int i) {
number = i;
}
/**
*
*/
public RegistroActionForm() {
super();
// TODO Auto-generated constructor stub
}
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param request The HTTP Request we are processing.
* @return
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getEmail() == null || getEmail().length() < 6) {
errors.add("wrongemail", new ActionMessage("errors.email", "This e-mail"));
}
if (getPass() == null || getPass().length() < 5) {
errors.add("wrongpass", new ActionMessage("errors.minlength", "Password", "6"));
}
return errors;
}
}
structs-config.xml
Código:
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="RegistroActionForm" type="com.myapp.struts.RegistroActionForm"/>
<form-bean name="LoginActionForm" type="com.myapp.struts.LoginActionForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="login" path="/Login.do"/>
<forward name="registro" path="/Registro.do"/>
</global-forwards>
<action-mappings>
<action input="/login.jsp" name="LoginActionForm" path="/login" scope="request" type="com.myapp.struts.LoginAction">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
<action input="/registro.jsp" name="RegistroActionForm" path="/registro" scope="session" type="com.myapp.struts.RegistroAction">
<forward name="FAILURE" path="/Mensaje.jsp"/>
</action>
<action path="/Login" forward="/login.jsp"/>
<action path="/Registro" forward="/registro.jsp"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="com/myapp/struts/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>
<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>
Registro.jsp y Login.jsp son los otros dos archivos.
El problema es que imprime una pag en blanco despues de hacer click en el boton registrarse.