servlet的问题
本人新手,目前有个紧急问题向请教各位大虾。本人用servlet提示以下问题:Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.ncsq_jsp._jspService(ncsq_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:240)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
servlet代码如下:
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
Popwindow pop = new Popwindow();
String action=request.getParameter("action");
if (action.equals("add"))
{
News news = null;
try {
news = new News();
}
catch (Exception e) {
e.printStackTrace();
}
String type = request.getParameter("type");
System.out.println("typeid:"+type);
String title = request.getParameter("title");
String content = request.getParameter("content");
int count=0;
String date=new Time().getYMDHMS();
news.setPid(type);
news.setTitle(title);
news.setContent(content);
news.setCount(count);
news.setDate(date);
addNews(news);
String url="../nc138/manager/News_Manage.jsp";
out.println(pop.Js_ErrorInfo_redirect("新闻添加成功!",url));
}
if (action.equals("mod"))
{
String id = request.getParameter("id");
String pid = request.getParameter("type");
String title = request.getParameter("title");
String content = request.getParameter("content");
String date=new Time().getYMDHMS();
modNews(pid,title,content,date,id);
out.println(pop.Js_ErrorInfo_redirect("新闻修改成功!","../nc138/manager/News_Manage.jsp"));
}
out.flush();
out.close();
}
public void addNews(News news){
DBConnectionManager db = DBConnectionManager.getInstance();
Connection conn = db.getConnection("idb");
String add_sql = "insert into nc138_news (pid,title,content,count,date) values (?,?,?,?,?)";
try {
PreparedStatement ps =conn.prepareStatement(add_sql);
ps.setString(1,news.getPid());
ps.setString(2,news.getTitle());
ps.setString(3,news.getContent());
ps.setInt(4,news.getCount());
ps.setString(5,news.getDate());
ps.executeUpdate();
}
catch (Exception e) {
db.freeConnection("idb",conn);
e.printStackTrace();
}
db.freeConnection("idb",conn);
}
调用了该页面的JSP代码如下:
<jsp:useBean id="newsServ" scope="session" class="com.nc138.servlet.NewsServlet" />
<jsp:useBean id="str" scope="session" class="com.nc138.servlet.StrServlet" />
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<%
String type="南昌商情";
ResultSet rs=newsServ.queryNewsByType(type,12);
while(rs.next()){
String id=rs.getString("id");
String title1=rs.getString("title");
String title2="";
String title=null;
if(title1!=null)
title2=title1.trim();
if(title2!=null)
title=str.toLengthStrRight(title2,30);
String date=null;
String date2=rs.getString("date");
if(date2!=null)
date=date2.substring(5,10);
%>
<tr height="6">
<td width="25" height="20" valign="top">・</td>
<td height="20" valign="top">
<a class="link3" href="News_show.jsp?ID=<%=id%>" target="_blank"><%=title%></a>
</td>
<td width="30" height="20" valign="top"><%=date%></td>
</tr>
<%}%>
</table>
问题很急,希望各位大虾指点小弟啊,感激不尽。超急!!!!!!!1