| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 910 人关注过本帖
标题:servlet的问题
只看楼主 加入收藏
liqiang05
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-20
收藏
 问题点数:0 回复次数:13 
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
搜索更多相关主题的帖子: servlet 
2007-04-01 18:28
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
你用的是javabean吧,怎么说是servlet呢。

我的网站 http://www.
2007-04-02 17:33
黄袖标
Rank: 4
等 级:贵宾
威 望:13
帖 子:676
专家分:0
注 册:2007-3-22
收藏
得分:0 
空指针,找找

我胡汉三又回来啦!物是人非啊,只有静夜思大大还在。
2007-04-02 17:41
pyzheng
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2004-12-5
收藏
得分:0 
ResultSet rs=newsServ.queryNewsByType(type,12);
--------------對象沒有創建 怎么用﹖

-----------人間太苦﹐成仙太難------------
2007-04-03 16:24
神vLinux飘飄
Rank: 1
等 级:新手上路
威 望:1
帖 子:309
专家分:0
注 册:2007-1-27
收藏
得分:0 
以下是引用风月_无边在2007-4-2 17:33:27的发言:
你用的是javabean吧,怎么说是servlet呢。

何处此言?


泛出微微的蓝色的光,像有生命般涌动着,闪烁着,平滑而优美,达到了机械和美学结合的最高境界
2007-04-04 10:52
liqiang05
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-20
收藏
得分:0 
ResultSet我在JavaBean里有方法返回,所以不用在JSP页面里创建
2007-04-04 14:32
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
得分:0 

我日5楼的马甲


2007-04-04 21:12
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 
我跟着日,楼上的快点
2007-04-06 20:32
lov
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-12-23
收藏
得分:0 

不要在这里灌水了吧

2007-04-06 21:25
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 
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"));
}
没有看到有关于这个红字的方法的申明啊!

2007-04-06 23:24
快速回复:servlet的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019973 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved