Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why no config in jspInit() method?

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are translated into Servlet before serving to any client. And so JSPs also have the same life cycle after translation (init(), service() and destroy()).

My question is, why jspInit() method (corresponding to init() method of servlet) doesn't take any config parameter???

Thanks.
 
Stefan Evans
Bartender
Posts: 1717
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should it?
What would you pass to it?

The servlet gets passed its ServletConfig information, which is documented in web.xml for that servlet.
You don't have an entry in web.xml for a JSP, so you don't

Don't lose hope however. If you look at the Api page for JspPage, you will see that it specifies that getServletConfig() must return the desired info, while in the init method.

So you can get hold of it regardless.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Evans:

The servlet gets passed its ServletConfig information, which is documented in web.xml for that servlet.
You don't have an entry in web.xml for a JSP, so you don't


Did you mean, we can't provide configuration parameter (config init paramater) in web.xml for JSP.

If yes then it is NOT right. we can give init paramaters to JSP also through web.xml:



 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As originally posted by Stefan Evans:

Don't lose hope however. If you look at the Api page for JspPage, you will see that it specifies that getServletConfig() must return the desired info, while in the init method.


Enough said.
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since JSPs are dynamically converted into servlets, it is not possible to give init paramaters for a particular JSP.
However, if you precompilation like JSPC, then it will generate a xml file which you would need manually copy paste its contents to web.xml. In this case you can give the init parameters for each JSP file.

Hope this helps.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why jspInit() method (corresponding to init() method of servlet) doesn't take any config


Just to add to this, even in the servlet version, init() is overridden , and not the init with the ServletConfig.


And,,,,
Since JSPs are dynamically converted into servlets, it is not possible to give init paramaters for a particular JSP.


Why not?? Is ths not equivalent to what rathi ji specified.

<servlet><jsp-file>/MyJSP.jsp</jsp-file><init-param><param-name>key</param-name><param-value>value</param-value></init-param></servlet>
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was not aware of this. Thanks geetu for updating my knowledge.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey but wait i minute..
i had read so.. but seems to have a problem...



This is my configuration..
and my jsp has



'null' is printed. Can someone explain why is that ??
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can try mapping servelt to the jsp file and then try again.

<servlet-mapping>
<servlet-name>oneInApp2</servlet-name>
<url-pattern>>/jsp/oneInApp2.jsp</url-pattern>
<servlet-mapping>
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats correct Dilip.I didnt have the mapping in my web.xml
Thanks
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more oint tht hs to be noted..
if u access the jsp.. directly .. without goin through the servelt mapping.. u will never get the init parameters.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetu lalchandani:
One more oint tht hs to be noted..
if u access the jsp.. directly .. without goin through the servelt mapping.. u will never get the init parameters.


How to access JSP with going through the servelt mapping???
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:


How to access JSP with going through the servelt mapping???


Just through normal way.
[ May 26, 2006: Message edited by: Dilip Kumar Jain ]
 
Peter Hu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jspInit method is provided by the jsp convention. It's not the equivalent of the servlet init method, rather it provides the similar opportunety to do your initialization work. The servlet's init method still exists and lives well inside jsp. The reason jsp doesn't inherit directly, instead offers the jspInit, is that it wants to make sure the execution of init() is proper without being diverted accidentally by non-experienced programmers. If you want the config, override the init method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic