哥哥,姐姐们快救救我啊!!!

wtzychwhd 2009-12-28 11:34:07
一个博客的Java web项目 在servlet 中 我这样写道:
/*********** 保存博主信息 *****************/
session.setAttribute("master",masterBean);
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
request.getRequestDispatcher("../../../front/FrontIndex.jsp").forward(request, response);
System.out.println( "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
}
运行结果是 AAAAAAAAAAA
2009-12-28 11:28:29 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet indexServlet threw exception
java.lang.NullPointerException
at com.zzti.servlet.IndexServlet.doPost(IndexServlet.java:63)
at com.zzti.servlet.IndexServlet.doGet(IndexServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:55)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
2009-12-28 11:28:29 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at com.zzti.servlet.IndexServlet.doPost(IndexServlet.java:63)
at com.zzti.servlet.IndexServlet.doGet(IndexServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:55)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
我检查了N遍 不知哪里错误!!! 请哥哥,姐姐们答疑!!!!
...全文
306 点赞 收藏 33
写回复
33 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ZMycm 2010-01-01
学习了~
回复
androidmvc 2010-01-01
AAAAAA>..
能打印出来证明是下面错了。。。
关键就在接下来的一行。。。。。
你用request.getRequestDispatcher("../../../front/FrontIndex.jsp").forward(request, response); 跳转之后还会打印么。。。。。。所以说,,
就是在你写的跳转这个地方出了问题。。。。forward之后不会出现代码问题。。。
那么就是你的getRequestDispatcher()中的路径的问题、。、、、好好检查路径!!!!!
回复
张祥龙 2010-01-01
我觉得你之前的路径是对的,然后作用域里放的集合有空的,在jsp页面调用时出现空指针,发JSP页面看看
回复
kevin_qust 2009-12-31
request.getRequestDispatcher("../../../front/FrontIndex.jsp").forward(request, response); 你进入这个请求之前的request路径 和 ("../../../front/FrontIndex.jsp")不匹配
回复
VilenZYP 2009-12-31
看到LZ 贴的代码。。我的眼睛花了。。

还是不看了。。路过,顺便说一下。。LZ的代码,应该增加点换行。。
回复
humor200 2009-12-31
明显是路径问题。
回复
把注解去掉吧...自动生成的这 @Override 貌似没用...
眼花...
找错,是程序员的一大能力..额.....
回复
wj84507657 2009-12-31
servlet。。。。现在项目还有用servlet写的。。。。过时了吧
回复
lining86yc 2009-12-30
[Quote=引用 22 楼 sweatcoffee 的回复:]
路径问题
[/Quote]又见菩提MM
回复
春春 2009-12-29
Sorry 看到了.
回复
春春 2009-12-29
/*********** 保存博主信息 *****************/
session.setAttribute("master",masterBean);
中的masterBean有声明吗?
回复
sweatcoffee 2009-12-29
路径问题
回复
wtzychwhd 2009-12-29
问题还是没被解决,现在没有空指针问题了:却还是找不到FrontIndex.jsp,一运行iE中弹出404页面,我有检查了很多遍 不知原因,现在我把程序传出去,你们来看一下,调试调试,把你们的邮箱告诉我吧。下面是这个servlet

package com.zzti.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zzti.dao.ArticleDao;
import com.zzti.dao.ArticleTypeDao;
import com.zzti.dao.FriendDao;
import com.zzti.dao.LogonDao;
import com.zzti.dao.PhotoDao;
import com.zzti.dao.WordDao;
import com.zzti.bean.MasterBean;

public class IndexServlet extends HttpServlet {
private static MasterBean masterBean;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
ArticleDao articleDao = new ArticleDao();
ArticleTypeDao artTypeDao = new ArticleTypeDao();
PhotoDao photoDao = new PhotoDao();
WordDao wordDao=new WordDao();
FriendDao friendDao=new FriendDao();

/********** 获取在主页面的内容显示区中显示的内容 *********/
//从tb_article数据表中获取前3篇文章
List articleList=articleDao.queryArticle(-1,null);
request.setAttribute("articleList",articleList);
//从tb_photo数据表中获取前8张照片
List photoList=photoDao.queryPhoto("sub");
request.setAttribute("photoList",photoList);

/********** 获取在页面侧栏中显示的内容 *********/
/* 从tb_word数据表中获取前5条留言 */
List wordList=wordDao.queryWord("sub");
session.setAttribute("wordList",wordList);
/* 从tb_article数据表中获取前5章推荐文章 */
List artTJList=articleDao.queryArticle(4,"sub");
session.setAttribute("artTJList",artTJList);
/* 从tb_friend数据表中获取前5位好友信息 */
List friendList=friendDao.queryFriend("sub");
session.setAttribute("friendList", friendList);

/********** 获取文章类别 *******************/
/* 从tb_articleType数据表中获取文章类别 */
List artTypeList=artTypeDao.queryTypeList();
session.setAttribute("artTypeList",artTypeList);

/*********** 保存博主信息 *****************/
session.setAttribute("master",masterBean);
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAA");
request.getRequestDispatcher("/front/FrontIndex.jsp").forward(request,response);
System.out.println( "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
}
static{
LogonDao logonDao=new LogonDao();
masterBean=logonDao.getMaster();
}
}
回复
whereusejava 2009-12-28
楼上分析的有道理
顶。。。
回复
TzSword 2009-12-28
是这句吗?
request.getRequestDispatcher("../../../front/FrontIndex.jsp").forward(request, response);

RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
页面的路径是相对路径。forward方式只能跳转到本web应用中的页面上
将下面的删掉..
回复
lijun3159 2009-12-28
request.getRequestDispatcher("../../../front/FrontIndex.jsp").
空指针,好好检查一下路径
回复
TzSword 2009-12-28
at com.zzti.servlet.IndexServlet.doPost(IndexServlet.java:63)
你的Servlet的第63行代码贴一下 是个空指针。。。
回复
coveking 2009-12-28
每个链接写绝对路径就没事了。 包括图片和转向的jsp页面。
不要写半截路径。同一级目录下的路径 要么就是写绝对路径,要么就不加“/” 不能写成 “/login.jsp” 可写成 “login.jsp”
回复
zjy05023036 2009-12-28
天啊,啊好哦复杂啊..厉害啊
回复
gaozliang2009 2009-12-28
可能是你给的路径有问题吧,你在浏览器中单独访问那个页面,测试下地址有问题不?
回复
加载更多回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2009-12-28 11:34
社区公告
暂无公告