日期:2014-05-18  浏览次数:20844 次

struts2.x依赖注入无效的问题
package com.loginCheck;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
private String userName=null;
private String userPassword=null;


@Override
public String execute(){
if(userName != null) {
if(userName.equals("wuyanxue")) {

return SUCCESS;
}
}
System.out.println(userName+" "+userPassword);
return ERROR;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getUserName() {
return userName;
}

public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}

public String getUserPassword() {
return userPassword;
}

}


这是Action类

----------------------------------------

这是jsp页面的表单

<s:form action="login?request_locale=en_US" method="get">
      <s:textfield name="userName" key="loginUserName" ></s:textfield>
      <s:password name="userPassword" key="loginUserPassword" ></s:password>
      <s:submit key="submit"></s:submit>
     </s:form>

----------------------------------------


这是struts.xml的配置


<struts>
 
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="myResources"></constant>


<package name="example" namespace="" extends="struts-default">
<global-exception-mappings>
<exception-mapping result="Exception" exception="java.lang.Exception">
</exception-mapping>
</global-exception-mappings>
<action name="login" class="com.loginCheck.LoginAction">
            <interceptor-ref name="logger" />
            <interceptor-ref name="timer" />
         <exception-mapping result="SQLException" exception="java.sql.SQLException"></exception-mapping>
            <result name="success">
             /loginSuccess.jsp
            </result>
            <result name="error">
             /loginFail.jsp
            </result>
        </action>

    </package>

</struts>




---------------