首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2013-09-11 
帮忙看下 struts2下PrintWriter out response.getWriter()出错package com.sunmq.actionimport java.i

帮忙看下 struts2下PrintWriter out = response.getWriter();出错
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)




[解决办法]
HttpServletResponse response=null;//你都把它设为null

用 this.response 就可以获得到
[解决办法]
HttpServletResponse response=null;
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();

你的response都还没有值。。。 你就设置setContentType,你说他能不报错不?
[解决办法]
java.lang.NullPointerException
com.sunmq.action.CheckUserAction.execute(CheckUserAction.java:23)//这句空指针了,在23行。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行