This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatching

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,
Can anybody give me a code for the following purpose:
I want to forward a request from Servlet to JSP using RequestDispatcher interface's forward method.problem i am facing is how to give a url(either absolute or relative for JSP).

Extra Info: I am using Weblogic 6.1 where i have copied Servlet .class files in classes folder, whereas JSP is located in DefaultWebApp.

thanx in advance
Shrinivas
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out ServletContext.getRequestDispatcher() and getNamedDispatcher()

Dave
 
Heonkoo Lee
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the servlet url path defined in web.xml. Say, your servlet is called by http://server.com/MyApp/MyServlet. Then from the servlet you can forward to a JSP like:

// Use the relative path from the servlet.
RequestDispatcher rd = request.getRequestDispatcher("Result.jsp");
rd.forward(request, response);


// If servlet uri is http://server.com/MyApp/someDir/MyServlet and jsp is right under web root directory,
// by using relative path from servlet
RequestDispatcher rd = request.getRequestDispatcher("../Result.jsp");
// by using relative path from host server
RequestDispatcher rd = request.getRequestDispatcher("/MyApp/Result.jsp");
rd.forward(request, response);

Hope this helps.
[ April 03, 2005: Message edited by: Heonkoo Lee ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want an example, go get SimpleMVC from http://simple.souther.us
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic