当前位置: 代码迷 >> Java Web开发 >> jsp空指针报错解决思路
  详细解决方案

jsp空指针报错解决思路

热度:4829   发布时间:2013-02-25 21:12:14.0
jsp空指针报错
<%!
Vector v = new Vector();
int i = 1;
ServletContext application;
synchronized void sendMessage(String s) {
i ++;
v.add("No." + i + "," + s);
application.setAttribute("message", v);
}
%>
  <%
String name = request.getParameter("name");
String title = request.getParameter("title");
String messages = request.getParameter("message");
if(name == null) { 
name = "guest" + (int)(Math.random()*10000);
}
if(title == null) {
title = "无标题";
}
if(messages == null) {
messages = "无信息";
}
String s = "Name:" + name + "#" + "Title" + title + "#" + "Content:" + "<br>" + messages;
sendMessage(s);
out.println("您的信息已提交!");
%>

请高手们帮忙解决一下

------解决方案--------------------------------------------------------
首先,凡是涉及到错误的问题,请先把错误堆栈信息贴出来,免得大家还得猜测在哪里。。。


然后:你这定义是想干啥?
ServletContext application;
打算让它能变出东西来啊?
其实application可以直接使用的,如果你别画蛇添足的去声明它的话。。。


如果打算写,就写在函数里面吧:
ServletContext application = getServletContext();
------解决方案--------------------------------------------------------
探讨
首先,凡是涉及到错误的问题,请先把错误堆栈信息贴出来,免得大家还得猜测在哪里。。。


然后:你这定义是想干啥?
ServletContext application;
打算让它能变出东西来啊?
其实application可以直接使用的,如果你别画蛇添足的去声明它的话。。。


如果打算写,就写在函数里面吧:
ServletContext application = g……
  相关解决方案