Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling JSP from Servlet

 
Amit Lonkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am tring to call a JSP page from the servlet. I have written the follwing code. The request is not forwared to the JSP. and the control remains in the servlet.
try {
// Set the attribute and Forward to UserLogin.jsp
RequestDispatcher rd =
getServletConfig().getServletContext).getRequestDispatcher("/jsp/UserLogin.jsp");
// forward the request and response to target
rd.forward(request,response);
return;
} catch (Exception ex) {
System.out.println("Caught Exception in Sending jpspage im Main Servlet : " + ex.getMessage());
}
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai!
Try by removing getServletConfig() part..
Rgds
Manohar
 
Amit Lonkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manohar Karamballi:
Hai!
Try by removing getServletConfig() part..
Rgds
Manohar

Hi manohar
This still does not work.
Amit
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Exception is thrown (if any)?

 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit
I was just going through your code.Why have you written the return statement after the rd.forward(request,response); statement.Another thing.....I do not know if its a typing error on your part while sending the post or its an error in ur code...but your getServletContext() method is missing the starting bracket.As Mike said do you get any exceptions?
Regards
sanj
[This message has been edited by sanj singh (edited December 17, 2001).]
 
Jason Kilgrow
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Lonkar:
Hi
I am tring to call a JSP page from the servlet. I have written the follwing code. The request is not forwared to the JSP. and the control remains in the servlet.

How about trying:
String dispatchto = "MyJsp.jsp";
RequestDispatcher dispatch = null;
response.encodeURL(dispatchto);
dispatch = request.getRequestDispatcher(dispatchTo);
dispatch.forward(request, response);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic