This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlets

 
nastik pandit
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys, we can forward request using request's or context's requestDispatcher.In which case we will use request, and in which case we will use context? also whats the difference between / and ../. Please help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, a few things that will help you out here on the Ranch.

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "servlets" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the

Secondly, not everyone who helps people out here is a "guy".
 
Anutosh Swamy
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Krishna,

We can forward a request either by using the RequestDispatcher() of ServletContext interface or the ServletRequest interface, the point when to use ServletContext or ServletRequest is that the ServletRequest looks for the resources in the same context (same webapp) to which the invoking servlet belongs.

Moreover the pathname used in the RequestDispatcher() of ServletContext must begin with a "/" which is an absolute path.

The pathname used in the RequestDispatcher() of ServletRequest interface can be an absolute path or a relative path means it can start with “/” or “../..”.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That kind of questions are usually answered in the API docs.

http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)

Please familiarize yourself with the API docs and learn to find/understand them.

Edit: links fixed, UBB parser didn´t seem to take the last parenthesis in the generated URL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic