Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jspInit() cant see implicit variable application

 
MarkShane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Why cant the method jspInit() within a JSP see
the implicit variable application?. You can see
it within scriplets. Will it not see it during the
Translation phase?.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is because the implicit variables are NOT instance or static members of the generated JSP class. They are local variables of the _jspService(...) method. To access the objects such as ServletContex, ServletConfig in the jspInit() method, you've to use the standard servlet way i.e. this.getServletConfig().getServletContext().
HTH,
Paul.
 
MarkShane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
thanks for your response. I was able to get hold
of application object via the class ServletContext. Is it possible to obtain a session
object in a similar manner?.
 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mark,
(1) jspInit() method can not get a hold of session object, b'coz it is the service method who matters for session.
If we mention session attribute of page directive true then _jspService method will create session object for us.
(2) Moreover, jspInit() method always be called only once for an instance, whereas if we mention jsp page as thread safe, it will create multiple threads to serv multiple requests(in turn, multiple sessions). At this time a single instance (jspInit() method) will be shared between multiple sessions.
So it is not possible get hold of session object in jspInit() method.
hope this helps,
Best regards, Dharmin
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic