帮忙看下 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.
NullPointerExceptioncom.sunmq.action.CheckUserAction.execute(CheckUserAction.java:23)//这句
空指针了,在23行。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html