当前位置: 代码迷 >> Java Web开发 >> 为利用application在服务器端公用和可以暂时保存数据的特点,设计一个记事本 ...
  详细解决方案

为利用application在服务器端公用和可以暂时保存数据的特点,设计一个记事本 ...

热度:319   发布时间:2013-04-30 19:40:31.0
为利用application在服务器端公用和可以暂时保存数据的特点,设计一个记事本程序
为利用application在服务器端公用和可以暂时保存数据的特点,设计一个记事本程序。
码调试报错。请指教

index.jsp中的主要代码:
<body>
   <form action=notepad.jsp method="post" name=form>
   标题:<input type="text" size=16 name="title"/>
   <p>请输入你的留言:<br>

   <textarea rows="8" cols="40" name="content" wrap="phsical"></textarea>
   <br>
   <input type="submit" value="提交" name="submit">  
   </form>
  </body>


notepad.jsp中的主要代码:
<body>
<%
     Date date=new Date();
     String datetime=date.toLocaleString();
     String title=request.getParameter("title");
     String message=request.getParameter("content");
     
     //将各项整合为一个字符串
     String s=title+"#"+message+"#"+datetime;
     //从application中获取原有的留言内容
     Vector v=(Vector)application.getAttribute("mess");
     v.add(s);
     application.setAttribute("mess",v);
     Vector vv=(Vector)application.getAttribute("mess");
//下面的循环从VV中取出每条留言,并分析分项内容
for(int i=0;i<vv.size();i++)
{
     String messages=(String)vv.elementAt(i);
     StringTokenizer fenxi=new StringTokenizer(messages,"#");
     int j=0,m=i+1;
     String str[]=new String[3];
//循环分析messages字符串的内容     
while(fenxi.hasMoreTokens())
{
     str[j]=fenxi.nextToken();
     byte a[]=str[j].getBytes("ISO-8859-1");
     str[j]=new String(a);
     j++;
}
out.print("<center>");
out.print("********************************<br>");
out.print("<Table border>");
out.print("<tr>");
out.print("<td>第"+m);
out.print("楼&nbsp;&nbsp;标题:"+str[0]);
out.print("&nbsp;&nbsp;时间:"+str[2]);
  out.print("</td>");
out.print("</tr>");
out.print("<tr>");
  out.print("<td>");
out.print("内容:"+str[1]);
out.print("</td>");
out.print("</tr>");
out.print("</Table>");
out.print("</center>");

}

  %>
  </body>
报错:
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:522)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    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)


root cause

java.lang.NullPointerException
    org.apache.jsp.notepad_jsp._jspService(notepad_jsp.java:95)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    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.20 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.20
搜索更多相关主题的帖子: title  method  action  name  

----------------解决方案--------------------------------------------------------
有人吗?
----------------解决方案--------------------------------------------------------
@版主
----------------解决方案--------------------------------------------------------
有人吗
----------------解决方案--------------------------------------------------------
Vector v=(Vector)application.getAttribute("mess");
if(v==null){
      v= new Vector();
  }
这下面加一个这个就OK了
原理是 当mess没有信息时 是一个null值
null是不能add属性的

----------------解决方案--------------------------------------------------------
  相关解决方案