Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

getServletContext in jspInit

 
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.
 
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
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • 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.
 
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.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can try this:

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