Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

diffrence b/w calling of getRequestDispatcher form request and getServletCotext.

 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody tell me the difference by calling the getRequestDispatcher() by request object and ServletContext object.

Please tell me the difference reqarding the scope of the two object

I suppose there is only the differnce of the scope of the request and response.
One diff is using request object request.getRequestDispatcher(path). we pass argument as relative path as well as the root of the application through /(forward slash)
But in ServletContext we only call forward through /(forward slash) for the path.
Please give the explaination regarding the scope of the two object.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chidanand Chauhan:

One diff is using request object request.getRequestDispatcher(path). we pass argument as relative path as well as the root of the application through /(forward slash)
But in ServletContext we only call forward through /(forward slash) for the path.
Please give the explaination regarding the scope of the two object.



You just did.
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then is there any concept of request object and ServletContext object.
like request is a thread safe and context not related to this i am talking about this
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the methods of RequestDispatcher:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html

Hint:
Notice that they both require a servletRequest and servletResponse object as arguments.
What does this say about thread safety?
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What does this say about thread safety?


I couldn't find a mention about thread safety in the docs.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My point was that, no matter how you obtain the requestDispatcher, you have to pass it a reference to the current request whenever you want to use it.
Since doing so limits it's use to a particular request, it doesn't really matter if you get the dispatcher from the request itself or from the servlet
context.

The real difference is the one that you pointed out.
suppose there is only the differnce of the scope of the request and response.
One diff is using request object request.getRequestDispatcher(path). we pass argument as relative path as well as the root of the application through /(forward slash)
But in ServletContext we only call forward through /(forward slash) for the path.

[ December 24, 2005: Message edited by: Ben Souther ]
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
My point was that, no matter how you obtain the requestDispatcher, you have to pass it a reference to the current request whenever you want to use it.
Since doing so limits it's use to a particular request, it doesn't really matter if you get the dispatcher from the request itself or from the servlet
context.




[ December 24, 2005: Message edited by: Ben Souther ]


Hi Ben

Thanks But my question is why did they provide this method through context or request object.

Suppose if i call this method through ServletRequest then what is the diff between ServletContext object. Is it related to the Thread safety or not. Please guide for this.

Thanks
Chidanand Chauhan
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chidanand Chauhan:
Suppose if i call this method through ServletRequest then what is the diff between ServletContext object. Is it related to the Thread safety or not.


No, it is not related to thread-safty here. And for why?? you can refer to Ben's last reply, prior my post, in this thread.
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, atlast i found that its not related to thread safety.
Thanks to Ben for giving the excellent explanation.

Thanks,
Chidanand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic