首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2 Action中获取request, response对象的 几种 步骤

2012-11-09 
struts2 Action中获取request, response对象的 几种 方法struts2 Action中获取request, response对象的方

struts2 Action中获取request, response对象的 几种 方法
struts2 Action中获取request, response对象的方法 

第一种方法:

ActionContext ctx = ActionContext.getContext();                 HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);                 HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);                   //ServletActionContext.APPLICATION;          //ServletActionContext.SESSION;          //ServletActionContext.PAGE_CONTEXT;        



第二种方法:
实现     ServletRequestAware
public class TestAction implements ServletRequestAware{      /**---*/      public void setServletRequest(HttpServletRequest request) {// 要复写这个方法request.setAttribute("key","value"); }}


第三种:更简单的一种。。
HttpServletRequest request = ServletActionContext.getRequest();




1 楼 zhanger 2009-05-09   HttpServletRequest request = ServletActionContext.getRequest();
这样貌似也行吧 2 楼 caizhongda 2009-05-10   renny 写道
HttpServletRequest request = ServletActionContext.getRequest();这样貌似也行吧


嗯。谢谢哈。。你这样也行哈。我补上你这个哈。

热点排行