社区
Java EE
帖子详情
struts2 response问题
yu98041154
2009-11-24 06:05:18
我用
HttpServletResponse response = ServletActionContext.getResponse();
在ACTION里获取response返回的为什么是NULL
是不是还要配置什么东西啊。谢谢!!
...全文
178
11
打赏
收藏
struts2 response问题
我用 HttpServletResponse response = ServletActionContext.getResponse(); 在ACTION里获取response返回的为什么是NULL 是不是还要配置什么东西啊。谢谢!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yu98041154
2009-11-24
打赏
举报
回复
。。。。。。引错一个类。郁闷!
谢谢。大家
道光2008
2009-11-24
打赏
举报
回复
你看看这个吧
http://cppmayi.javaeye.com/blog/493865
yu98041154
2009-11-24
打赏
举报
回复
这两个应该同时能获取到或者获取不到吧?
yu98041154
2009-11-24
打赏
举报
回复
ServletContext servletContext = ServletActionContext.getServletContext();
System.out.println(servletContext);
这个是我随便写的。测试下。
道光2008
2009-11-24
打赏
举报
回复
你到底是获取ServletContext 还是response,不说清楚
yu98041154
2009-11-24
打赏
举报
回复
package org.goldratio.action;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.goldratio.DBUtil.DBAccess;
import org.goldratio.Util.RespUtil;
import org.json.JSONException;
import org.json.JSONObject;
public class MyJsonAction extends ActionSupport
{
private String jsonString;
private int totalCount;
private int pageIdx = 0;
public String execute() throws Exception
{
ServletContext servletContext = ServletActionContext.getServletContext();
System.out.println(servletContext);
JSONObject jsp = new JSONObject();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter pw = response.getWriter();
得到的是NULL
道光2008
2009-11-24
打赏
举报
回复
参考下:
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport{
public String execute() {
ServletActionContext.getResponse();}
}
viper211
2009-11-24
打赏
举报
回复
我的做法是ACTION的父类实现ServletRequestAware, ServletResponseAware,ServletContextAware
其中保存一个
protected HttpServletRequest request;
protected HttpServletResponse response;
protected HttpSession session;
protected ServletContext context;
ACTION中便可以获得
yu98041154
2009-11-24
打赏
举报
回复
[Quote=引用 2 楼 zl3450341 的回复:]
HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
[/Quote]
我看了源码那个ServletActionContext.getResponse(); 其实就是你写的(HttpServletResponse)ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
但是我还是取不出来啊。返回就是NULL
zl3450341
2009-11-24
打赏
举报
回复
HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
jy02363756
2009-11-24
打赏
举报
回复
不需要了! 直接拿就可以
Struts2
视频_全面开战
本Java视频教程对
Struts2
庞杂的技术点进行抽丝剥茧,提炼出企业开发的核心技术和重要技能。每个技术点都配备案例和代码,对于拦截器、
Struts2
运行流程分析、值栈等技术点的讲授更是深入解析源代码,授之以渔。
struts2
获取
response
Struts2
获取
response
的两种方式: public class DepartmentAction extends BaseAction{ private Map request; //private HttpServlet
Response
response
; }
Struts2
中获取Request,
Response
的几种方法
在
Struts2
中的没有像Struts1那样必须要在Action类中写个execute()方法,只需要是个返回字符串的方法即可(有时候也不需要返回值),在
struts2
中经将原有的servlet中request参数和
response
参数封装在拦截器中,可是有...
Struts2
获取request和
response
Struts2
的Action抛弃了request、
response
等Servlet API,如果需要获取,可以通过 Servlet
struts2
中使用
response
public class ProcessDefinitionAction extends ActionSupport implements Servlet
Response
Aware{ ... private HttpServlet
Response
response
; @Override public void setServlet
Response
(Http
Java EE
67,514
社区成员
225,878
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章