File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Accessing Implicit objects in jspinit() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing Implicit objects in jspinit()" Watch "Accessing Implicit objects in jspinit()" New topic
Author

Accessing Implicit objects in jspinit()

Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
I am aware of the fact that the implicit objects, viz. application, session, request, response, etc. are not available until the service() (or jsp_service() method) is called.
In that case, how do I go about initializing/configuring a servlet with some object instances for the other servlets in the web application to use.My requirement is to have start-up servlet which is configured with a name/value pair for an object of class Information.This class would contain the name of the webmaster, his address and other details.
I guess, the only way to do it is using the ServletConfig class.But does it allow us to store customized objects instances of class like Information?I would not like to store it as web_master_name=sandeep,address=some_address, etc., as there are many such name/value pairs
I could have used the setAttribute("Information", i) with any of the implicit objects in the jspinit() (or init()) method, had any of these objects been available.
Please advise a workaround for this.
Thanks in advance.
Regards
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 26, 2001).]
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
You have access to the servlet context (application) in jspInit() because the JspPage interface extends javax.servlet.Servlet, which has the getServletConfig() method:

Additionally, you can specify context parameters in the web.xml file with <context-param>...</context-param>. See the JSP spec or the webapp DTD for details.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Phil,
Thanks very much for the response and the code
------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
If you would like to use web.xml method, here is a sample code.
http://www.javaranch.com/ubb/Forum7/HTML/003152.html
regds
maha anna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing Implicit objects in jspinit()