0

I am making simple login page and trying to validate it using struts ValidatorForm but its not working. But same code worked for DynaValidatorForm. Not able to understand what's problem. It is not showing any error when I click login button. Here is my code.

login.jsp

 <body>  
    <div style="color:red">  
                <html:errors />  
            </div>  
            <html:form action="/Login" >  
                User Name : <html:text name="LoginForm" property="username" /> <br>  
                Password  : <html:password name="LoginForm" property="password" /> <br>  
                <html:submit value="Login" />  
            </html:form>  
            </body>  

LoginAction.java

public class LoginAction extends Action  

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

    LoginForm loginForm=(LoginForm) form;  
     String userName = loginForm.getUsername();  
        String password = loginForm.getPassword();  
        if(userName.equals("sumeet") )  
        {  
            return mapping.findForward("success");  
        }  
        else  
        {  
            return mapping.findForward("failure");  
        }  

struts.config

  <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">  
    <struts-config>  
    <form-beans>  
            <form-bean name="LoginForm" type="com.ibm.Forms.LoginForm" >  
            </form-bean>  
    </form-beans>  

        <global-exceptions>  
        </global-exceptions>  

        <global-forwards>  
        </global-forwards>  

        <action-mappings>  
            <action name="LoginForm" path="/Login" scope="session" input="/login.jsp" type="com.ibm.Action.LoginAction" cancellable="true" validate="true">  
            <forward name="success" path="/success.jsp"/>  
            </action>  
        </action-mappings>  

        <message-resources parameter="test2.resources.ApplicationResources"/>  
        <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>  

valdiation.xml

  <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd" >  
    <form-validation>  

    <formset>  
            <form name="LoginForm">  
                <field property="username" depends="required">  
                                </field>  

    <field property="password" depends="required,minlength">  
            <arg1 key="${var:minlength}" name="minlength" resource="false"/>  
              <var>  
              <var-name>minlength</var-name>  
              <var-value>6</var-value>  
              </var>  
              </field>  
              </form>  
           </formset>  
    </form-validation>  

Thank you.

4

1 回答 1

0

您缺少.dohtml 表单的 action 属性。您不需要两个输入中的 name 属性。

<html:form action="/Login.do" >  
    User Name : <html:text property="username" /> <br>  
    Password  : <html:password property="password" /> <br>  
    <html:submit value="Login" />  
</html:form>
于 2013-03-14T11:44:24.997 回答