帮忙看下 struts2下PrintWriter out = response.getWriter();出错

aiq 2011-07-25 09:00:43
package com.sunmq.action;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.xwork2.ActionSupport;

public class CheckUserAction extends ActionSupport {
private String type;

public String execute() throws IOException {
HttpServletResponse response=null;
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.print("<script>alert('成功');window.location.reload();</script>");
return SUCCESS;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

}

出错如下
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
com.sunmq.action.CheckUserAction.execute(CheckUserAction.java:23)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)


...全文
411 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuodim1 2012-09-18
  • 打赏
  • 举报
回复
楼上正解!
xcvxcvxcvcxvxcv 2011-09-02
  • 打赏
  • 举报
回复
还有如果你用的是struts2的话是不可以 return success的; 一定要return null 才会有值!!!!!!!
xcvxcvxcvcxvxcv 2011-09-02
  • 打赏
  • 举报
回复
HttpServletResponse response = ServletActionContext.getResponse();
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 heiboyyang 的回复:]

java.lang.NullPointerException
HttpServletResponse response;
not
HttpServletResponse response=null;
[/Quote]
这样才是实例了一个。不然你都设置为NUll了 你说怎么不为空呢?
HeiBoyYang 2011-07-25
  • 打赏
  • 举报
回复
java.lang.NullPointerException
HttpServletResponse response;
not
HttpServletResponse response=null;

aiq 2011-07-25
  • 打赏
  • 举报
回复
那怎么改下呢
Davidtsang 2011-07-25
  • 打赏
  • 举报
回复
java.lang.NullPointerException
com.sunmq.action.CheckUserAction.execute(CheckUserAction.java:23)//这句空指针了,在23行。
aiq 2011-07-25
  • 打赏
  • 举报
回复
response.setContentType("text/html; charset=UTF-8");
去掉还是同样的错误
zl3450341 2011-07-25
  • 打赏
  • 举报
回复
HttpServletResponse response=null;
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();

你的response都还没有值。。。 你就设置setContentType,你说他能不报错不?
zn85600301 2011-07-25
  • 打赏
  • 举报
回复
HttpServletResponse response=null;//你都把它设为null

用 this.response 就可以获得到

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧