Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

why no config in jspInit() method?  RSS feed

 
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.
 
Bartender
Posts: 1845
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:



 
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.
 
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.
 
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 ]
 
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.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!