Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect jsp from servlet RequestDispatcher

Tags:

jsp

servlets

I want to redirect JSP page from one servlet. All JSP pages are under Web Content. not under Web-INF. I have a problem of calling that JSP pages. I got 404 errors. problem with path.

How can I call jsp pages under Web Content?

ServletContext context = getServletContext();
                 RequestDispatcher dispatcher = context.getRequestDispatcher("/thankYou.jsp");
                 dispatcher.forward(request,response);

Thanks ahead.

PROBLEM SOLVED !

like image 218
kitokid Avatar asked Nov 01 '11 06:11

kitokid


2 Answers

I solved the problem using RequestDispatcher like this:

RequestDispatcher requestDispatcher; 
requestDispatcher = request.getRequestDispatcher("/thankYou.jsp");
requestDispatcher.forward(request, response);
like image 183
kitokid Avatar answered Nov 22 '22 16:11

kitokid


A slightly cleaner way to write this code is:

request.getRequestDispatcher("/thankyou.jsp").forward(request, response);
like image 36
ryandlf Avatar answered Nov 22 '22 17:11

ryandlf