• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getServletContext in jspInit

 
Amit Goyal
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I call getServletContext() method directly in overriden jspInit method inside a jsp. If yes, from where it is coming , I mean from which interface it is coming.
 
anil kumar
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Amit

Yes You can call,It is comming from Servlet interface.

Not only you can call getServletConfig() also

The generated Servlet extends HttpJspBase.And

HttpJspBase extends JspPage

This is the signature of the JspPage



public interface JspPage extends Servlet


Thanks

Anil Kumar
[ July 15, 2007: Message edited by: anil kumar ]
 
Amit Goyal
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil,

Thanks for your reply.

I am asking for getServletContext not for getServletConfig.


Regards,

Amit Goyal
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the ServletContext by using the implicit application object within the JSP.

The following link will explain that for you

JSP Application Object
 
Amit Goyal
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its ok to access the servletcontex by using application implicit object or by using pageContext.getServletContext(), I have no issues with it.
My only concern is that, can I call getServletContext method directly in a jspInit method because in Head First on page 308 (in an example) it is written that we can call it directly.
But i did not get any interface in the heirarchy which have getServletContext method.
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can.

jspinit() introduces servletConfig object. Once you get hold of it you can call ServletContext object using getServletContext() of servletConfig interface.
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can try this:

this.getServleConfig.getServletContext();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic