• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

difference between getContext(String uri) and getServletContext()

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I want to know the difference between

getContext(String url) and getServletContext()

Both of them return the ServletContext object though and one takes a path to the specified resource.
Inspite of using getServletContext(), first we can take the real path of the application and pass that path
to getContext() and get the ServletContext object. So i am confused what is the difference between two of
them? Can getContext(String url) can be used alternatively instead of getServletContext().

Thanks.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Zaidi wrote:Inspite of using getServletContext(), first we can take the real path of the application and pass that path
to getContext() and get the ServletContext object.



What?? getServletContext() gets the context object for the current web application. There is not getContext(String uri) method in the GenericServlet class. I think it is available in ApplicationContext of tomcat. The getContext(String uri) gets the context object for the uri specified. This can be used to get a context object of a different web application...
 
Ben Zaidi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit, it was pretty helpful. I figured it out though by looking at the API's. In any case it was a great explanation.

Thanks
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the explanation Ankit.

Am I right in assuming that the exam does not cover any of the API that is Tomcat specific? It's only for the Servlet API that is common across implementations?

Thanks,
Joshua Smith
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Am I right in assuming that the exam does not cover any of the API that is Tomcat specific?


Of course. No container dependant question.

There is not getContext(String uri) method in the GenericServlet class.


Just to make sure nobody thinks that there is no such method at all, I'd like to add that there is one here : javax.servlet.ServletContext#getContext(java.lang.String)
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophe. I really need to go through the API again ...
 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Ben Zaidi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris and Ankit.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic