Pessoal, gostaria que alguém me ajudasse a configurar o struts…
Tenho os seguintes arquivos:
- RegisterForm (bean para o formulario de login)
[code]
package app;
import org.apache.struts.action.*;
public class RegisterForm extends ActionForm {
protected String username;
protected String password1;
protected String password2;
//getters e setters
}[/code]
- RegisterAction (valida o login)
ignorem a classe UserDirectory…
package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class RegisterAction extends Action {
public ActionForward perform (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
if(password1.equals(password2)) {
try {
UserDirectory.getInstance().setUser(username, password1);
return mapping.findForward("success");
} catch (UserDirectoryException e) {
return mapping.findForward("failure");
}
}
return mapping.findForward("failure");
}
}
- struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>
-
web.xml (naum coloquei nada)
-
register.jsp
<%@ page language="java" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<html>
<body>
<html:form action="register.do">
Username: <html:text property="username"/><br>
Pass1: <html:password property="password1"/><br>
pass2: <html:password property="password2"/><br>
<html:submit value="register"/>
</html:form>
</body>
</html>
- failure.html e success.html (naum interessa muito)
O q tem de errado??? tem q fazer alguma coisa no web.xml???+