1

我已经完成了我的登录验证。它工作正常,但输入正确usernameand后password,没有执行任何操作,成功登录后也没有打开 JSP 页面。

这是我的登录表单:

         <s:form validate="true"   action="login">
        <br>
         <table class="bg" cellspacing="0">
        <tr class="logindiv">
          <td >
          </td>`enter code here`
         <td>

       Sign In
       </td>
         </tr>

           <tr>
          <td>
          <s:textfield label="Username" name="obj2.user" cssStyle="height:25px;                   width:150px;"></s:textfield>
         </td>
              </tr>



            <tr>
       <td>
       <s:password label="Password" name="obj2.pass"  cssStyle="height:25px;width:150px;"></s:password>
           </td>
            </tr>

                <tr>
                 <td>

             <center>&nbsp;
               <s:submit value="Login" cssClass="login"></s:submit>
              </center>

                  </td>
                 </tr>


            </table>

               </s:form>

struts.xml

          <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            "http://struts.apache.org/dtds/struts-2.0.dtd">



     <struts>

          <constant name="struts.devMode" value="true" />

           <package name="default" namespace="/" extends="struts-default">
       <action name="login" class="IndianUserActionModule.indianAction" method="Login">
          <result name="input">index.jsp</result>
         <result name="success">IndianHome.jsp</result>
         <result name="fail">index.jsp</result>
      </action>

         </package>

        </struts>
4

1 回答 1

0

In your struts configuration you map the action to a particular namespace of the package config. But in your JSP form you map an action to a default namespace. These are different namespaces and your action config isn't found in the default namespace, so it fails. You should use namespace attribute of your s:form tag to specify a namespace used to map the action. For example

<s:form validate="true" namespace="/"  action="login"> 

There's an example that would let you better understand the namespaces concept.

于 2014-06-29T08:00:41.453 回答