简体   繁体   English

转发到tomcat中的jsp时出错?

[英]Getting Error while forwarding to jsp in tomcat?

In my hello world program on tomcat i am not able to forward my request from servlet to jsp page.Here are my locations:- 在tomcat的hello world程序中,我无法将我的请求从servlet转发到jsp页面。这是我的位置:-

servlet location is webapps\\hello\\WEB-INF\\classes\\test servlet的位置是webapps \\ hello \\ WEB-INF \\ classes \\ test

Location of jsp page(RequestObjectInJSP) is webapps\\hello jsp页面(RequestObjectInJSP)的位置是webapps \\ hello

My code to forward the request is 我转发请求的代码是

req.getRequestDispatcher("RequestObjectInJSP").forward(req, res);

But it gives the error The requested resource (/hello/RequestObjectInJSP) is not available. 但是它给出了错误。请求的资源(/ hello / RequestObjectInJSP)不可用。

Not sure what i am missing here? 不知道我在这里想念什么?

Question2:- similarily if i try to forward the request from one servlet to another servlet(both lying under same folder) does not work .Below is the code snippet 问题2:-同样,如果我尝试将请求从一个servlet转发到另一个servlet(都位于同一文件夹下)不起作用,则下面是代码片段

req.getRequestDispatcher("servlet2").forward(req, res); req.getRequestDispatcher(“ servlet2”)。forward(req,res);

If i give the mapping of servlet2 in web.xml then it starts working.As per my understanding if we forward the request from one servlet to another and both lying under webinf/classes folder it should work without giving the sevlet 2 mapping in web.xml. 如果我在web.xml中提供servlet2的映射,则它开始工作。据我的理解,如果我们将请求从一个servlet转发到另一个servlet,并且两者都位于webinf / classes文件夹下,则它应该工作而无需在Web中提供sevlet 2映射。 xml。 Right? 对?

Your JSP file is missing the JSP extension. 您的JSP文件缺少JSP扩展名。 Add it and fix the path accordingly. 添加它并相应地修复路径。

req.getRequestDispatcher("RequestObjectInJSP.jsp").forward(req, res);

As to your 2nd question, yes definitely you need to map the servlet on an URL pattern in order to be able to forward to the URL(!!) of the given servlet. 关于第二个问题,是的,您肯定需要在URL模式上映射servlet,以便能够转发到给定servlet的URL(!!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM