开发者

Getting Error while forwarding to jsp in tomcat?

开发者 https://www.devze.com 2023-04-11 01:05 出处:网络
In my hello world program on tomcat i am not able to forward my reques开发者_运维知识库t from servlet to jsp page.Here are my locations:-

In my hello world program on tomcat i am not able to forward my reques开发者_运维知识库t from servlet to jsp page.Here are my locations:-

servlet location is webapps\hello\WEB-INF\classes\test

Location of jsp page(RequestObjectInJSP) is 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.

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

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. Right?


Your JSP file is missing the JSP extension. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号