简单的一个输出,总是报错,请帮忙,谢谢
<%@page language="java" contentType="text/html" pageEncoding="UTF-8" %>
<%
response.getWrite().write("{name:'',age:26,email:'sss@eee.com'}");
%>
-------------------------------------------------------------------------------
An error has occurred. See error log for more details.
java.lang.NullPointerException
HTTP Status 500 -
--------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 4 in the jsp file: /person.jsp
The method getWrite() is undefined for the type HttpServletResponse
1: <%@page language="java" contentType="text/html" pageEncoding="UTF-8" %>
2:
3: <%
4: response.getWrite().write("{name:'',age:26,email:'sss@eee.com'}");
5: %>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
[解决办法]
<%out.print("{name:'',age:26,email:'sss@eee.com'}");%>
[解决办法]
response.getWrite(). 这个为null 所以报异常了。
[解决办法]
response 对象未声明
[解决办法]
注意
response.getWrite()
和
response.getWriter()
的区别@@@@
[解决办法]
response.getWrite()改成out