Girish B Mohite wrote:
> Hi EveryBody
>
> I am trying to create a pool of Database connections
> I want this code to be executed only once that is as wee do in the init()
> method of servlets.Thats why i have written a servlet for this
> Now here onwards all my JSP's should be extending this servlet.Will i be able
> to do this.
> Finally i have done this and the code excutes the init method of the servlet
> first,but after that the control doesnt comes to my JSp.It gives an error at
> that point
>
> Has anyone tried this type of thing
> Thanx in advance
>
Here's an easy way to deal with this situation, without even needing to have your
JSP pages extend a servlet:
* Create a servlet whose init() method creates the connection pool
in the usual way.
* Once the pool is created, store it as an servlet context attribute (which
is the same as an application scope bean in JSP pages):
com.mycompany.mypackage.ConnectionPool myPool =
new ConnectionPool(...);
getServletContext().setAttribute("pool", myPool);
* In the web.xml file, configure this servlet to be loaded at startup time,
so that the connection pool will be established immediately (rather than
on the first request).
* In a JSP page that needs access to the pool, use a <jsp:useBean>
tag like this:
<jsp:useBean id="pool" class="com.mycompany.mypackage.ConnectionPool"
scope="application"/>
>
> Girish
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets