You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by 0 8 <01...@gmail.com> on 2006/06/22 22:46:00 UTC

Running code on Tomcat startup

Hello,

I have a newbie Tomcat question.

A search application I need to work with uses RMI.  When I start
Tomcat, is there a way I can run the code to create an object that I
can reference in a JSP later?

What I need to run is straight forward:

ClientServices cs =
com.mycompany.searchapp.ClientServicesFactory.getInstance("RMI",
parms); // Get the ClientServices
cs.Login(strDomain, strUser, strPassword); // Login

Can I run this and reference the object cs from my JSP?

If someone could point me in a general direction it would be
appreciated.  If there's a better way to handle this, I'm open to
suggestions.

Thanks,
Matt

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Running code on Tomcat startup

Posted by Pid <p...@pidster.com>.
lookup ServletContextListener

Andrew Braae wrote:
> I've handled this by using a servlet filter that intercepts all requests
> (something like this in your web.xml file)...
> 
> <filter-mapping>
>      <filter-name>Do Startup Filter</filter-name>
>      <url-pattern>/*</url-pattern>
> </filter-mapping>
> 
> Then inside the do.. method you can set up your object and attach to either
> a context such as your session or to the ServletContext (if you want it
> globally available).
> 
> However, I don't know know if this is the best way - one problem is that
> the
> startup cost is suffered by the first user to hit the site, whereas it
> would
> be better if the startup was performed when tomcat itself starts up.
> This is
> not such an issue I guess for a site that is hammered the second it comes
> up.
> 
> 
> 
> On 6/23/06, 0 8 <01...@gmail.com> wrote:
>>
>> Hello,
>>
>> I have a newbie Tomcat question.
>>
>> A search application I need to work with uses RMI.  When I start
>> Tomcat, is there a way I can run the code to create an object that I
>> can reference in a JSP later?
>>
>> What I need to run is straight forward:
>>
>> ClientServices cs =
>> com.mycompany.searchapp.ClientServicesFactory.getInstance("RMI",
>> parms); // Get the ClientServices
>> cs.Login(strDomain, strUser, strPassword); // Login
>>
>> Can I run this and reference the object cs from my JSP?
>>
>> If someone could point me in a general direction it would be
>> appreciated.  If there's a better way to handle this, I'm open to
>> suggestions.
>>
>> Thanks,
>> Matt
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Running code on Tomcat startup

Posted by Andrew Braae <an...@gmail.com>.
I've handled this by using a servlet filter that intercepts all requests
(something like this in your web.xml file)...

<filter-mapping>
      <filter-name>Do Startup Filter</filter-name>
      <url-pattern>/*</url-pattern>
</filter-mapping>

Then inside the do.. method you can set up your object and attach to either
a context such as your session or to the ServletContext (if you want it
globally available).

However, I don't know know if this is the best way - one problem is that the
startup cost is suffered by the first user to hit the site, whereas it would
be better if the startup was performed when tomcat itself starts up. This is
not such an issue I guess for a site that is hammered the second it comes
up.



On 6/23/06, 0 8 <01...@gmail.com> wrote:
>
> Hello,
>
> I have a newbie Tomcat question.
>
> A search application I need to work with uses RMI.  When I start
> Tomcat, is there a way I can run the code to create an object that I
> can reference in a JSP later?
>
> What I need to run is straight forward:
>
> ClientServices cs =
> com.mycompany.searchapp.ClientServicesFactory.getInstance("RMI",
> parms); // Get the ClientServices
> cs.Login(strDomain, strUser, strPassword); // Login
>
> Can I run this and reference the object cs from my JSP?
>
> If someone could point me in a general direction it would be
> appreciated.  If there's a better way to handle this, I'm open to
> suggestions.
>
> Thanks,
> Matt
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>