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.

Tom11
  • 2,419
  • 8
  • 30
  • 56
sambot
  • 63
  • 1
  • 2
  • 9

1 Answers1

0

You are missing the .do in the action attribute of the html form. You don't need the name attribute in both inputs.

<html:form action="/Login.do" >  
    User Name : <html:text property="username" /> <br>  
    Password  : <html:password property="password" /> <br>  
    <html:submit value="Login" />  
</html:form>
gunr2171
  • 16,104
  • 25
  • 61
  • 88