}
action動態訪問調用?下面來看非IOC方式的代碼
package loginAction;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
public class NoIoCAction extends ActionSupport{
? ? private String userName;
? ? private String password;
? ? /**
? ? ?* @return the userName
? ? ?*/
? ? public String getUserName() {
? ? ? ? return userName;
? ? }
? ? /**
? ? ?* @param userName the userName to set
? ? ?*/
? ? public void setUserName(String userName) {
? ? ? ? this.userName = userName;
? ? }
? ? /**
? ? ?* @return the password
? ? ?*/
? ? public String getPassword() {
? ? ? ? return password;
? ? }
? ? /**
? ? ?* @param password the password to set
? ? ?*/
? ? public void setPassword(String password) {
? ? ? ? this.password = password;
? ? }
? ? public String execute() throws Exception{
? ? ? ? if(getUserName().equals("QQ")&&getPassword().equals("123")){
? ? ? ? ? ? /*調用ServletActionContext的getRequest()方法獲取HttpServletRequest類的對象request對象。*/
? ? ? ? ? ? HttpServletRequest request=ServletActionContext.getRequest();
? ? ? ? ? ? //調用request對象的getSession()方法獲取session對象
? ? ? ? ? ? HttpSession session=request.getSession();
? ? ? ? ? ? //調用session對象的方法設置數據
? ? ? ? ? ? session.setAttribute("userName", this.userName);
? ? ? ? ? ? session.setAttribute("password", this.password);
? ? ? ? ? ? return SUCCESS;
}
else{
? ? ? ? ? ? return INPUT;
}
? ? }?
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态