Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

call

how to call jsp from servlet.

could you give me the exact syntax
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
  • 2
  • 2
1 Solution
 
fargoCommented:
here is a good explanation about redirects, forwards etc.
http://www.theserverside.com/discussions/thread.tss?thread_id=22795

use request dispatcher to call jsp from servlet

RequestDispatcher dispatcher = request.getRequestDispatcher("/relative/path/to/jsp");
dispatcher.forward(request, response);



0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
>> "/relative/path/to/jsp"


meaning

suppose my view.jsp is under wepapps/jsp.

how could i specify relative path for that
0
 
fargoCommented:
if your servlet is defined at the root path like

http://localhost:8080/myapp/yourservlet

then u can do the following

RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/view.jsp");
dispatcher.forward(request, response);

it means /jsp/view.jsp path is relative to your context path.
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
suppose i have username and password variable in servlet.

how could i pass that variables, and view in jsp textboxes
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now