473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Call servlet On Server Startup

How can i call a function automatically when the server started ?
Oct 3 '08 #1
5 4763
From where you want to call the function or which event do you want to perform?
Ask a question which is clear to understood .
Oct 3 '08 #2
acoder
16,027 Expert Mod 8TB
I don't think this is a JavaScript question unless you want to call this servlet from the client-side (in which case, you would use Ajax).

What server software is it? Even Java/JSP wouldn't be enough. You will need some server setting (I think Tomcat has this ability) to trigger this, or you could poll the server using a page on another server.
Oct 4 '08 #3
u can implement the ServletContextListener interface in a java class
to access 2 methods namely,
Expand|Select|Wrap|Line Numbers
  1. public void contextInitialized(ServletContextEvent e)
  2. {
  3. //your code here;
  4. }
  5.  
and
Expand|Select|Wrap|Line Numbers
  1. public void contextDestroyed(ServletContextEvent e)
  2. {
  3. //cleaning up;
  4. }
  5.  
from the parameter e you can access the context and write whatever code u wish to execute within the first of the two methods i mentioned.

and one more thing
add this code to your web.xml config file

<listener>
<listener-class>mypackage.myclass</listener-class>
</listener>
Oct 6 '08 #4
acoder
16,027 Expert Mod 8TB
Moved to the Java forum. If someone feels it doesn't belong here, please move to a more appropriate forum, thanks.

Moderator.
Oct 6 '08 #5
JosAH
11,448 Expert 8TB
How can i call a function automatically when the server started ?
A Servlet is bound to a certain application (or more of them) but a server has
to deal with all of them. There is no reason for a server to call a method from a
particular Servlet. Check your server documentation if it can handle callbacks
when it starts up.

kind regards,

Jos
Oct 6 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Morgan | last post by:
I'm trying to get php to run on my webserver as a Java Servlet, it works the first time but fails the second time and crashes the JVM with the following error: I have tried the latest versions...
2
by: Nischal Topno | last post by:
Hi, Is there any way to auto load/instantiate a new class of a servlet into the JVM (with shutting the web server) after replacing the old class with new one? For e.g., after a servlet is...
2
by: robert walker | last post by:
hi all, to my webapp named mrf, i have added load-on-startup tag to mrf\WEB-INF\web.xml so i added a snippet like so <servlet> <servlet-name>loadDbProperties</servlet-name>...
1
by: Farce Milverk | last post by:
Hi, Is it possible to have a Servlet on Server A call a Servlet on Server B (both running single instances of an identical webapplication) without using a Proxy setup? For example, if a request...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
1
by: sureshyerva | last post by:
i need a servlet to be loaded by the server on startup in my application. How it can be done.plz help me out...........
9
by: mjahabarsadiq | last post by:
Hi I have created a servlet that is to be started at the server startup. And I got it. In that I have created a object of another class and set it as a session attribute. What I am trying is...
3
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.