Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Calling JSP from Servlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai!
Try by removing getServletConfig() part..
Rgds
Manohar
 
Amit Lonkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Exception is thrown (if any)?

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic