主题:在线等待(帮忙必加分)!!!
代码:
<%@ page contentType="text/html; charset=gb2312" import="java.util.Date"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自Cookie存取日期/时间数据</title>
</head>
<body>
<center>
<font size="+5" color="blue">自Cookie存取日期/时间数据</font>
</center><hr><p></p>
<%
Date Now=new Date();//取得目前的系统时间
Cookie DateVal=new Cookie("DateVal",String.valueOf(Now.getTime()));
//要将保存至时间/日期转换为豪秒数
response.addCookie(DateVal);//将Cookie变量加入Cookie中
Cookie temp=null;
DateVal=null;//重设Cookie变量
Cookie[]cookies=request.getCookies();//取得Cookie数据
int cookielen=cookies.length;//取得Cookie变量数组的长度
if(cookielen!=0)//判断是否成功取得Cookie数据
{
for(int i=0;i<cookielen;i++)
{
temp=cookies[i];//取得cookie数组中的Cookie变量
if(temp.getName().equals("DateVal"))
{//判断是否取得名为DataVal的Cookie数据
DateVal=temp;
}
}
%>
<p></p>
Cookie中<font color="blue">DateVal</font>变量的值为<font color="red">
<%=new Date(Long.parseLong(DateVal.getValue()))%></font><p></p>
<% //取得DateVald的值后,将其转换为Long类型的数值,再以该数值建立Date变量,还原出日期/时间值
}
else//若无法取得Cookie数据则执行下面的语句
{
%>
无法取得Cookie<br>
<%
}
%>
</body>
</html>
运行后:
Apache Tomcat/4.0.4 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at org.apache.jsp.$024$jsp._jspService($024$jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:534)
这是什么意思?那错了???
-----------------------------------------------------------------------------
帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!
<%@ page contentType="text/html; charset=gb2312" import="java.util.Date"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自Cookie存取日期/时间数据</title>
</head>
<body>
<center>
<font size="+5" color="blue">自Cookie存取日期/时间数据</font>
</center><hr><p></p>
<%
Date Now=new Date();//取得目前的系统时间
Cookie DateVal=new Cookie("DateVal",String.valueOf(Now.getTime()));
//要将保存至时间/日期转换为豪秒数
response.addCookie(DateVal);//将Cookie变量加入Cookie中
Cookie temp=null;
DateVal=null;//重设Cookie变量
Cookie[]cookies=request.getCookies();//取得Cookie数据
int cookielen=cookies.length;//取得Cookie变量数组的长度
if(cookielen!=0)//判断是否成功取得Cookie数据
{
for(int i=0;i<cookielen;i++)
{
temp=cookies[i];//取得cookie数组中的Cookie变量
if(temp.getName().equals("DateVal"))
{//判断是否取得名为DataVal的Cookie数据
DateVal=temp;
}
}
%>
<p></p>
Cookie中<font color="blue">DateVal</font>变量的值为<font color="red">
<%=new Date(Long.parseLong(DateVal.getValue()))%></font><p></p>
<% //取得DateVald的值后,将其转换为Long类型的数值,再以该数值建立Date变量,还原出日期/时间值
}
else//若无法取得Cookie数据则执行下面的语句
{
%>
无法取得Cookie<br>
<%
}
%>
</body>
</html>
运行后:
Apache Tomcat/4.0.4 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at org.apache.jsp.$024$jsp._jspService($024$jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:534)
这是什么意思?那错了???
-----------------------------------------------------------------------------
帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!帮忙必加分!!!