x_2268567875
_九少
2017-08-06 17:34

HTTP Status 500 求大神帮忙

  • java

按照书上写的代码 不是知道为啥总是出现 HTTP Status 500 错误
代码如下:

cookie.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>


<%
String str="12";
int number=Integer.parseInt(str);
%>
该数的平方为:<%=number*number %>

<%
Cookie cookie=new Cookie("number",str);
cookie.setMaxAge(600);
response.addCookie(cookie);
%>
到达cookie1

cookie1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>


<%
String str=null;
Cookie[] cookies=request.getCookies();
for(int i=0;i {
if(cookies[i].getName().equals("number"))
{
str=cookies[i].getValue();
break;
}
}
int number=Integer.parseInt(str);
%>
该数的立方为:<%=number*number*number %>


错误显示为:
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: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
org.apache.jsp.cookie1_jsp._jspService(cookie1_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.


Apache Tomcat/6.0.13

求大神帮忙啊

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答