简体   繁体   中英

Invoking a jsp from a servlet using request dispatcher?

I am trying to invoke a jsp from a servlet as below.

request.getRequestDispatcher("/Hello.jsp").forward(request, response);

mine is maven project. jsp is located in below location.

SomeProject/src/main/webapp/Hello.jsp

But i am getting HTTP ERROR: 404. how can i mention jsp path?

Thanks!

您应该先检查是否可以通过该路由访问jsp, http://host:port/context_root/Hello.jsp可以在Web浏览器中工作?

use

request.getRequestDispatcher("Hello.jsp").forward(request, response);

and see if it works

first you have to define the RequestDispatcher method,

Like this:

RequestDispatcher rd=request.getRequestDispatcher("filename.jsp");
rd.forward(request,response);

Make sure your jsp file is in the same directory of the servlet directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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