方法三:
取得真实类型的request,session,application
用得比较少的方法:
package cn.edu.hpu.getValue; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class LoginAction3 extends ActionSupport { private HttpServletRequest request; private HttpSession session; private ServletContext application; public LoginAction3(){ request=ServletActionContext.getRequest(); session=request.getSession(); application=session.getServletContext(); } public String execute(){ request.setAttribute("r1", "r1"); session.setAttribute("s1", "s1"); application.setAttribute("a1", "a1"); return SUCCESS; } }
方法四:
取得真实类型的request,session,application
用得比较少的方法:
package cn.edu.hpu.getValue; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; public class LoginAction4 extends ActionSupport implements ServletRequestAware{ private HttpServletRequest request; private HttpSession session; private ServletContext application; public String execute(){ request.setAttribute("r1", "r1"); session.setAttribute("s1", "s1"); application.setAttribute("a1", "a1"); return SUCCESS; } @Override public void setServletRequest(HttpServletRequest request) { this.request=request; this.session=request.getSession(); this.application=session.getServletContext(); } }
转载请注明出处:http://blog.csdn.net/acmman/article/details/44239105
时间: 2024-10-03 23:09:55