Hi,
i've got a problem. i've done in my app an form where user must input
login and password then this form is validated and then a want to test
if this values are good or bad (LoginCheck.java), but form is null,
why? How can I get login and password values and test if they are
good?
now my app:
(struts-config.xml)
<action path="/Login" forward="/pages/Login.jsp"/>
<action path="/login-check" type="peceka.LoginCheck">
<forward name="success" path="/pages/LogOK.jsp" />
<forward name="error" path="/Login.do" />
</action>
<action path="/login-submit" type="peceka.LoginAction"
name="loginForm" scope="request" validate="true" input="input">
<forward name="input" path="/Login.do" />
<forward name="success" path="/login-check.do" />
</action>
...
<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>
Login.jsp:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html>
<head>
<title><bean:message key="loginForm.title"/></title>
<html:base/>
</head>
<body bgcolor="white">
<logic:messagesPresent>
<bean:message key="errors.header"/>
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr />
</logic:messagesPresent>
<html:form action="login-submit">
<html:hidden property="action"/>
<table border="0" width="100%">
<tr>
<th align="left">
<bean:message key="loginForm.login"/>
</th>
<td align="left">
<html:text property="login" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<th align="left">
<bean:message key="loginForm.password"/>
</th>
<td align="left">
<html:password property="password" size="60" maxlength="60"/>
</td>
</tr>
<tr>
<td>
<html:submit property="submit">
<bean:message key="button.login"/>
</html:submit>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
LoginAction.java:
package peceka;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public final class LoginAction extends Action {
private Log log =
LogFactory.getFactory().getInstance(this.getClass().getName());
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Was this transaction cancelled?
if (isCancelled(request)) {
if (log.isInfoEnabled()) {
log.info(
" "
+ mapping.getAttribute()
+ " - Registration transaction was cancelled");
}
removeFormBean(mapping, request);
return (mapping.findForward("success"));
}
return mapping.findForward("success");
}
protected void removeFormBean(
ActionMapping mapping,
HttpServletRequest request) {
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope())) {
request.removeAttribute(mapping.getAttribute());
} else {
HttpSession session = request.getSession();
session.removeAttribute(mapping.getAttribute());
}
}
}
}
LoginForm.java:
package peceka;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;
public final class LoginForm extends ValidatorForm implements Serializable {
private String action = null;
private String sLogin = null;
private String sPassword = null;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getLogin() {
return sLogin;
}
public void setLogin(String sLogin) {
this.sLogin = sLogin;
}
public String getPassword() {
return sPassword;
}
public void setPassword(String sPassword) {
this.sPassword = sPassword;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
action = null;
sLogin = null;
sPassword = null;
}
}
LoginCheck.java:
package peceka;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class LoginCheck extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws
Exception {
if ( form != null ) {
LoginForm loginForm = (LoginForm)form;
System.out.println("login: " + loginForm);
return(mapping.findForward("success"));
}
else {
System.out.println("error. form == null");
return ( mapping.findForward("error") );
}
}
}
Best Regards,
p.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]