日期:2014-05-18  浏览次数:20790 次

Cookie问题求救啊
下面这个程序刚开始还能运行得到结果,后来过了几分钟再运行就不行了,请问是什么原因啊??

<%
                                  //建立Cookie
String   cookieName   =   "sender ";
Cookie   cookie   =   new   Cookie(cookieName   ,   "Test_Content ");
cookie.setMaxAge(10);
response.addCookie(cookie);
%>
<%
                                    //读取有效Cookie
Cookie   []   cookies   =   request.getCookies();
Cookie   sCookie   =   null;
String   sName   =   null;
String   sValue   =   null;
out.print( " <table   border=1> ");
for(int   i=0;   i <cookies.length;i++)
{
sCookie   =   cookies[i];
sName   =   sCookie.getName();
sValue   =   sCookie.getValue();
%>
<tr> <td> <%=sName%> </td> <td> <%=sValue%> </td>
<%
}
out.print( " </table> ");
%>

下面是异常信息:
HTTP   Status   500   -  

exception  

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root   cause  

java.lang.NullPointerException
org.apache.jsp.theObject.createCookie_jsp._jspService(createCookie_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


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




------解决方案--------------------
cookie.setMaxAge(10);
应该是cookie过期了