• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why no config in jspInit() method?

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic