2013年11月18日星期一

struts2.x dependency injection invalidity of

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;
}

}


This is the Action class

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

This is a form jsp page







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


This is struts.xml configuration


<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>




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

Problem Description: When I was in jsp page form, enter the account "wuyanxue" any password when console output null null

This shows struts2.x with jsp form values ​​are not instantiated LoginAction


exactly is the problem in any place where there is a problem with my code do ?


------ Solution ------------------------------------ --------
also need to add :

 <interceptor-ref name="defaultStack">  
                <param name="exception.logEnabled">true</param>  
                <param name="exception.logLevel">ERROR</param>  
            </interceptor-ref> 

http://www.iteye.com/problems/89992
------ For reference only --------------------- ------------------
seeking a big god help
------ For reference only ------------ ---------------------------
thanks for the answer

没有评论:

发表评论