You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Debashis Ghosh <de...@ibusinesshub.com> on 2001/06/14 03:57:55 UTC

How can I make tomcat to instantiate a class

Hi,
Can anyone suggest How can I make tomcat to instantiate a class so that i can 
access it from my 
jsp or servlet as an application level variable.Basically i want to 
instatiate one connection pool class so 
that i can access it from my servlet to get an connection object out of it.

On Wednesday 13 June 2001 06:47 pm, you wrote:
> Below is good advice. If the login page does not
> come up (btw, what happens does it just take you
> direct to the protected resource?) the first place I would
> look is the tomcat config files. So basically I would
> double-check server.xml and the web-xml for your app.
> If you are sure they are correct and you still have a problem
> you might want to try posting the relevant sections to the list.
>
> If you do get JDBCRealm working with tomcat standalone then
> to integrate with apache you need to add
>
> JkMount /examples/jsp/security/login/j_security_check ajp13
> (or ajp12 if using mod_jserv) to httpd.conf to tell apache
> to delegate the handling of this bit of magic to tomcat.
>
> andrew
>
> On Wed, 13 Jun 2001, you wrote:
> > > Mark, I appreciate your help.   I have tried
> > > to adapt the examples and I believe I have everything
> > > in place.  However, apache just wont bring the login
> > > form when I try to access a protected resource.
> > > Would you have any idea where to look at for this problem?
> >
> > You might want to check and see if you can get a
> > JDBCRealm to work with tomcat standalone(i.e. accessing
> > you site as http://localhost:8080/... directly).
> > If this doesn't work get this working first and
> > that's a good place to start from.  Once you have
> > JDBCRealm working correctly then you can deal with
> > making sure it works when passed through apache.
> >
> >
> > ---
> > Michael Wentzel
> > Software Developer
> > Software As We Think - http://www.aswethink.com

Re: How can I make tomcat to instantiate a class

Posted by Luba Powell <lu...@bellatlantic.net>.
This awfully good...
----- Original Message -----
From: "Bo Xu" <bo...@cybershop.ca>
To: <to...@jakarta.apache.org>
Sent: Thursday, June 14, 2001 5:15 PM
Subject: Re: How can I make tomcat to instantiate a class


> > ...But actually my problem was to instantiate a class when
> > tomcat boots up...so that i can use that object across sessions.Can u
> > suggest something towarsd this.
> > [...]
>
> Hi :-)  I find the following is from servlet-2_3-pfd2-spec.pdf(for
> Servlet containers which supports Servlet spec2.3):
>
> *
> ...
> SRV.10.2.2 An Example of Listener Use
> To illustrate a use of the event scheme, consider a simple web application
> containing a number of servlets that make use of a database. The developer
> has provided a serv-let context listener class for management of the
database
> connection.
> 1. When the application starts up, the listener class is notified. The
> application logs on to the database, and stores the connection in the
> servlet context.
>
> 2. Servlets in the application access the connection as needed during
> activity in the web application.
>
> 3. When the web server is shut down, or the application is removed from
> the web server, the listener class is notified and the database connection
is
> closed.
> ...
>
>
> * and I think perhaps there is another way:
>    - make a "startupServlet", and in its "servlet-declaration" in
>      WEB-INF/web.xml, set the following:
>       <load-on-startup>1</load-on-startup>
>       now/so when TC is started, the "init" method of this
"startupServlet"
>       will be invoked by container
>    - in the "init" method in this "startupServlet", a SingleTon pattern
>      "startupUtility" is instantiated: for example, by invoking a public
static
>      "Factory method":
>       public void init(ServletConfig config) throws ServletException{
>           super.init(config);
>           ...
>           startupUtility.makeInstance();
>           ...
>       }
>
>    - now after a while(instantiating time),  a instance of  startupUtility
is
> available
>      (for example, a DBConnectionpool)
>
>
> Bo
> June 14, 2001
>
>
>


Re: How can I make tomcat to instantiate a class

Posted by Bo Xu <bo...@cybershop.ca>.
> ...But actually my problem was to instantiate a class when
> tomcat boots up...so that i can use that object across sessions.Can u
> suggest something towarsd this.
> [...]

Hi :-)  I find the following is from servlet-2_3-pfd2-spec.pdf(for
Servlet containers which supports Servlet spec2.3):

*
...
SRV.10.2.2 An Example of Listener Use
To illustrate a use of the event scheme, consider a simple web application
containing a number of servlets that make use of a database. The developer
has provided a serv-let context listener class for management of the database
connection.
1. When the application starts up, the listener class is notified. The
application logs on to the database, and stores the connection in the
servlet context.

2. Servlets in the application access the connection as needed during
activity in the web application.

3. When the web server is shut down, or the application is removed from
the web server, the listener class is notified and the database connection is
closed.
...


* and I think perhaps there is another way:
   - make a "startupServlet", and in its "servlet-declaration" in
     WEB-INF/web.xml, set the following:
      <load-on-startup>1</load-on-startup>
      now/so when TC is started, the "init" method of this "startupServlet"
      will be invoked by container
   - in the "init" method in this "startupServlet", a SingleTon pattern
     "startupUtility" is instantiated: for example, by invoking a public static
     "Factory method":
      public void init(ServletConfig config) throws ServletException{
          super.init(config);
          ...
          startupUtility.makeInstance();
          ...
      }

   - now after a while(instantiating time),  a instance of  startupUtility is
available
     (for example, a DBConnectionpool)


Bo
June 14, 2001




Re: How can I make tomcat to instantiate a class

Posted by Luba Powell <lu...@bellatlantic.net>.
This is what I suggest you do:

    Create Gateway class (login class) that metes out Session
    objects to callers via getMySession() method.
    Inside this method I would deserialize the bean object from the file and
added it as     an attribute inside the session.

    It is a common technique for passing Connection and Thread
    Pool objects within the session.

    Or simple change scope to session:
    <jsp:useBean id="counter" scope="page" class="javabean.Counter" />

    But I realize that programming with tags is very limited.

Hope this helps.
R/Luba

----- Original Message -----
From: "Debashis Ghosh" <de...@ibusinesshub.com>
To: <to...@jakarta.apache.org>
Sent: Thursday, June 14, 2001 2:29 PM
Subject: Re: How can I make tomcat to instantiate a class


> Hi Luba,
> Thanks for this . But actually my problem was to instantiate a class when
> tomcat boots up...so that i can use that object across sessions.Can u
suggest
> something towarsd this.
> Thanks
> debashis
> On Thursday 14 June 2001 08:18 am, you wrote:
> > JSP will do it for you.  Example:
> >
> > <html>
> > <body>
> >
> > <%@ page language="java" %>
> > <%@ page import="javabean.Counter" %>
> >
> > <!-- page, request, session, application  -->
> >
> > <jsp:useBean id="counter" scope="page" class="javabean.Counter" />
> >
> > <%
> >  out.println("Count from scriplet = " + counter.getCount());
> > %>
> >
> > <br>
> >
> > Count from jsp:getProperty=
> >  <jsp:getProperty name="counter" property="count" />
> >
> > </body>
> > </html>
> >
> >
> > ----- Original Message -----
> > From: "Debashis Ghosh" <de...@ibusinesshub.com>
> > To: <to...@jakarta.apache.org>
> > Sent: Wednesday, June 13, 2001 9:57 PM
> > Subject: How can I make tomcat to instantiate a class
> >
> > > Hi,
> > > Can anyone suggest How can I make tomcat to instantiate a class so
that i
> >
> > can
> >
> > > access it from my
> > > jsp or servlet as an application level variable.Basically i want to
> > > instatiate one connection pool class so
> > > that i can access it from my servlet to get an connection object out
of
> >
> > it.
> >
> > > On Wednesday 13 June 2001 06:47 pm, you wrote:
> > > > Below is good advice. If the login page does not
> > > > come up (btw, what happens does it just take you
> > > > direct to the protected resource?) the first place I would
> > > > look is the tomcat config files. So basically I would
> > > > double-check server.xml and the web-xml for your app.
> > > > If you are sure they are correct and you still have a problem
> > > > you might want to try posting the relevant sections to the list.
> > > >
> > > > If you do get JDBCRealm working with tomcat standalone then
> > > > to integrate with apache you need to add
> > > >
> > > > JkMount /examples/jsp/security/login/j_security_check ajp13
> > > > (or ajp12 if using mod_jserv) to httpd.conf to tell apache
> > > > to delegate the handling of this bit of magic to tomcat.
> > > >
> > > > andrew
> > > >
> > > > On Wed, 13 Jun 2001, you wrote:
> > > > > > Mark, I appreciate your help.   I have tried
> > > > > > to adapt the examples and I believe I have everything
> > > > > > in place.  However, apache just wont bring the login
> > > > > > form when I try to access a protected resource.
> > > > > > Would you have any idea where to look at for this problem?
> > > > >
> > > > > You might want to check and see if you can get a
> > > > > JDBCRealm to work with tomcat standalone(i.e. accessing
> > > > > you site as http://localhost:8080/... directly).
> > > > > If this doesn't work get this working first and
> > > > > that's a good place to start from.  Once you have
> > > > > JDBCRealm working correctly then you can deal with
> > > > > making sure it works when passed through apache.
> > > > >
> > > > >
> > > > > ---
> > > > > Michael Wentzel
> > > > > Software Developer
> > > > > Software As We Think - http://www.aswethink.com


Re: How can I make tomcat to instantiate a class

Posted by Debashis Ghosh <de...@ibusinesshub.com>.
Hi Luba,
Thanks for this . But actually my problem was to instantiate a class when 
tomcat boots up...so that i can use that object across sessions.Can u suggest 
something towarsd this.
Thanks
debashis
On Thursday 14 June 2001 08:18 am, you wrote:
> JSP will do it for you.  Example:
>
> <html>
> <body>
>
> <%@ page language="java" %>
> <%@ page import="javabean.Counter" %>
>
> <!-- page, request, session, application  -->
>
> <jsp:useBean id="counter" scope="page" class="javabean.Counter" />
>
> <%
>  out.println("Count from scriplet = " + counter.getCount());
> %>
>
> <br>
>
> Count from jsp:getProperty=
>  <jsp:getProperty name="counter" property="count" />
>
> </body>
> </html>
>
>
> ----- Original Message -----
> From: "Debashis Ghosh" <de...@ibusinesshub.com>
> To: <to...@jakarta.apache.org>
> Sent: Wednesday, June 13, 2001 9:57 PM
> Subject: How can I make tomcat to instantiate a class
>
> > Hi,
> > Can anyone suggest How can I make tomcat to instantiate a class so that i
>
> can
>
> > access it from my
> > jsp or servlet as an application level variable.Basically i want to
> > instatiate one connection pool class so
> > that i can access it from my servlet to get an connection object out of
>
> it.
>
> > On Wednesday 13 June 2001 06:47 pm, you wrote:
> > > Below is good advice. If the login page does not
> > > come up (btw, what happens does it just take you
> > > direct to the protected resource?) the first place I would
> > > look is the tomcat config files. So basically I would
> > > double-check server.xml and the web-xml for your app.
> > > If you are sure they are correct and you still have a problem
> > > you might want to try posting the relevant sections to the list.
> > >
> > > If you do get JDBCRealm working with tomcat standalone then
> > > to integrate with apache you need to add
> > >
> > > JkMount /examples/jsp/security/login/j_security_check ajp13
> > > (or ajp12 if using mod_jserv) to httpd.conf to tell apache
> > > to delegate the handling of this bit of magic to tomcat.
> > >
> > > andrew
> > >
> > > On Wed, 13 Jun 2001, you wrote:
> > > > > Mark, I appreciate your help.   I have tried
> > > > > to adapt the examples and I believe I have everything
> > > > > in place.  However, apache just wont bring the login
> > > > > form when I try to access a protected resource.
> > > > > Would you have any idea where to look at for this problem?
> > > >
> > > > You might want to check and see if you can get a
> > > > JDBCRealm to work with tomcat standalone(i.e. accessing
> > > > you site as http://localhost:8080/... directly).
> > > > If this doesn't work get this working first and
> > > > that's a good place to start from.  Once you have
> > > > JDBCRealm working correctly then you can deal with
> > > > making sure it works when passed through apache.
> > > >
> > > >
> > > > ---
> > > > Michael Wentzel
> > > > Software Developer
> > > > Software As We Think - http://www.aswethink.com

Re: How can I make tomcat to instantiate a class

Posted by Luba Powell <lu...@bellatlantic.net>.
JSP will do it for you.  Example:

<html>
<body>

<%@ page language="java" %>
<%@ page import="javabean.Counter" %>

<!-- page, request, session, application  -->

<jsp:useBean id="counter" scope="page" class="javabean.Counter" />

<%
 out.println("Count from scriplet = " + counter.getCount());
%>

<br>

Count from jsp:getProperty=
 <jsp:getProperty name="counter" property="count" />

</body>
</html>


----- Original Message -----
From: "Debashis Ghosh" <de...@ibusinesshub.com>
To: <to...@jakarta.apache.org>
Sent: Wednesday, June 13, 2001 9:57 PM
Subject: How can I make tomcat to instantiate a class


> Hi,
> Can anyone suggest How can I make tomcat to instantiate a class so that i
can
> access it from my
> jsp or servlet as an application level variable.Basically i want to
> instatiate one connection pool class so
> that i can access it from my servlet to get an connection object out of
it.
>
> On Wednesday 13 June 2001 06:47 pm, you wrote:
> > Below is good advice. If the login page does not
> > come up (btw, what happens does it just take you
> > direct to the protected resource?) the first place I would
> > look is the tomcat config files. So basically I would
> > double-check server.xml and the web-xml for your app.
> > If you are sure they are correct and you still have a problem
> > you might want to try posting the relevant sections to the list.
> >
> > If you do get JDBCRealm working with tomcat standalone then
> > to integrate with apache you need to add
> >
> > JkMount /examples/jsp/security/login/j_security_check ajp13
> > (or ajp12 if using mod_jserv) to httpd.conf to tell apache
> > to delegate the handling of this bit of magic to tomcat.
> >
> > andrew
> >
> > On Wed, 13 Jun 2001, you wrote:
> > > > Mark, I appreciate your help.   I have tried
> > > > to adapt the examples and I believe I have everything
> > > > in place.  However, apache just wont bring the login
> > > > form when I try to access a protected resource.
> > > > Would you have any idea where to look at for this problem?
> > >
> > > You might want to check and see if you can get a
> > > JDBCRealm to work with tomcat standalone(i.e. accessing
> > > you site as http://localhost:8080/... directly).
> > > If this doesn't work get this working first and
> > > that's a good place to start from.  Once you have
> > > JDBCRealm working correctly then you can deal with
> > > making sure it works when passed through apache.
> > >
> > >
> > > ---
> > > Michael Wentzel
> > > Software Developer
> > > Software As We Think - http://www.aswethink.com


Re: How can I make tomcat to instantiate a class

Posted by Hemant Singh <he...@yahoo.com>.
HI Ghosh:
Make a class based on singelton pattern, which handles
the all database functionality, place this class in a
jar and place it in
TOMCAT_HOME/lib
Now you all servlets can access this same class file
and so using same session, Not sure whether and how
jsp can use it, can someone here clear this?
Hemant
--- Debashis Ghosh <de...@ibusinesshub.com> wrote:
> Hi,
> Can anyone suggest How can I make tomcat to
> instantiate a class so that i can 
> access it from my 
> jsp or servlet as an application level
> variable.Basically i want to 
> instatiate one connection pool class so 
> that i can access it from my servlet to get an
> connection object out of it.
> 
> On Wednesday 13 June 2001 06:47 pm, you wrote:
> > Below is good advice. If the login page does not
> > come up (btw, what happens does it just take you
> > direct to the protected resource?) the first place
> I would
> > look is the tomcat config files. So basically I
> would
> > double-check server.xml and the web-xml for your
> app.
> > If you are sure they are correct and you still
> have a problem
> > you might want to try posting the relevant
> sections to the list.
> >
> > If you do get JDBCRealm working with tomcat
> standalone then
> > to integrate with apache you need to add
> >
> > JkMount
> /examples/jsp/security/login/j_security_check ajp13
> > (or ajp12 if using mod_jserv) to httpd.conf to
> tell apache
> > to delegate the handling of this bit of magic to
> tomcat.
> >
> > andrew
> >
> > On Wed, 13 Jun 2001, you wrote:
> > > > Mark, I appreciate your help.   I have tried
> > > > to adapt the examples and I believe I have
> everything
> > > > in place.  However, apache just wont bring the
> login
> > > > form when I try to access a protected
> resource.
> > > > Would you have any idea where to look at for
> this problem?
> > >
> > > You might want to check and see if you can get a
> > > JDBCRealm to work with tomcat standalone(i.e.
> accessing
> > > you site as http://localhost:8080/... directly).
> > > If this doesn't work get this working first and
> > > that's a good place to start from.  Once you
> have
> > > JDBCRealm working correctly then you can deal
> with
> > > making sure it works when passed through apache.
> > >
> > >
> > > ---
> > > Michael Wentzel
> > > Software Developer
> > > Software As We Think - http://www.aswethink.com


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/