程序代码如下:
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher;
dispatcher = request.getRequestDispatcher("/WebContent/welcome.jsp");
dispatcher.include(request, response);
}
运行后出现错误:
HTTP Status 500 -type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionjavax.servlet.ServletException: File "/WebContent/welcome.jsp" not found
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:319)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.zyp.servlet.Aservlet.doPost(Aservlet.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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
如果把上文代码中的
dispatcher = request.getRequestDispatcher("/WebContent/welcome.jsp");
改为
dispatcher = request.getRequestDispatcher("/WebContent/welcome.html");
则不报错,而是在页面上显示
The requested resource (/mySecond/WebContent/welcome.html) is not available.
我感觉是路径有问题,但是不知道怎么改才能正确显示被包含的jsp和html页面的内容。
我的servlet的包名是com.zyp.servlet,除此之外没有修改任何工程目录,在下是新手,希望各位前辈不吝赐教,谢谢了!
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher;
dispatcher = request.getRequestDispatcher("/WebContent/welcome.jsp");
dispatcher.include(request, response);
}
运行后出现错误:
HTTP Status 500 -type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionjavax.servlet.ServletException: File "/WebContent/welcome.jsp" not found
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:319)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.zyp.servlet.Aservlet.doPost(Aservlet.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
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
如果把上文代码中的
dispatcher = request.getRequestDispatcher("/WebContent/welcome.jsp");
改为
dispatcher = request.getRequestDispatcher("/WebContent/welcome.html");
则不报错,而是在页面上显示
The requested resource (/mySecond/WebContent/welcome.html) is not available.
我感觉是路径有问题,但是不知道怎么改才能正确显示被包含的jsp和html页面的内容。
我的servlet的包名是com.zyp.servlet,除此之外没有修改任何工程目录,在下是新手,希望各位前辈不吝赐教,谢谢了!
另外补充一点:
1.工程名是mySecond;
2.welcome.jsp和welcome.html都是存在的(同一目录)
至少说明直接原因和引号有关。
另外,你可以看看tomcat那些jsp翻译成的servlet看看有这个文件吗?
这一句把本来作为字符串标记的引号给转义了,确实像你说的原因,可是
dispatcher = request.getRequestDispatcher("/WebContent/welcome.jsp");
如果不考虑路径问题,还能怎么写啊……我发誓我用的是eclipse,如果引号有问题一定会报错的。
仅仅把上面那一句的welcom.jsp的后缀改为html,也就是这样
dispatcher = request.getRequestDispatcher("/WebContent/welcome.html");
它就不报错了,而是在页面上显示
The requested resource (/mySecond/WebContent/welcome.html) is not available.
似乎又跟冒号没关系了
请求的路径不对。
检查下请求相同路径下其他jsp页面是否存在相同提示
工程名为:mySecond
页面路径:mySecond/WebContent/...
servlet类的包名为:com.zyp.servlet
其中有两个servlet 分别是Aservlet和Bservlet,问题中的代码取自Aservlet
确实是路径问题,代码改为
dispatcher = request.getRequestDispatcher("/welcome.jsp");
就没问题了。原本以为需要计算路径,看来是我想多了……
虽然耽误了不少时间,但总算是没给今天留下遗憾 哈哈!
今天第一次发帖,谢谢楼上两位前辈捧场!