Auto run Servlet

I want to develop a Servlet application that auto run on the server everyday.
The application should be satisfy the following requirement:
1. auto run on scheduled time
2. immediately run when the server restart
Any idea to do this ? Plse help
Also, any sample code or example is helpful.
Thanks

First, very thanks to all of you.
To sum up the idea, I have 2 ways
1. Use "crontab" to schedule application to run. (I'm using Linux with Tomcat)
2. Place the application in thread.
Which one is better ? And, I'm new to crontab. Is this possible to set the CLASSPATH and run application by using crontab. Now, i'm trying set CLASSPATH in crontab, but still not success.
If I use 2, place the application in thread. How to auto run application after the server restart ?
Thank you. I really want to know which one is a good solution before I start to write my program.
P.S. I not sure my question is a Servlet Technology question or not. So, I also place my question in Forum - New to Java Technology

Similar Messages

  • Auto-Run the servlet class at specificed time

    Hi,
    I am new to Jsp. I remember there is a feature where I define something in web.xml to auto-run a servlet at certain time.
    something like for everyday 4:30am, I want to clear up all the log file in my server.
    Please tell me how to do it or any reference.
    Thank you.

    if you are using a windows machine you can just schedule a task every day at that specified time and just run it. As far as the web.xml file telling the servlet to run at a specified time, I haven't heard of that. I just know that you can tell the server at what precedence you want the loading of the servlet(s).
    Hope this helps. Also, search the forum for more information on this matter. I'm sure that there are more posts on this matter that could assist you further.
    Good luck

  • Auto run application

    I want to develop a application that auto run on the server everyday.
    The application should be satisfy the following requirement:
    1. auto run on scheduled time
    2. immediately run after the server restart
    I suppose to use Servlet. plse give me any idea.
    sample code or example is helpful, Thank a lot !

    hi,
    if you use the solution with the crontab your java program is monitored. if the program crashes the cron starts it again. put you have to write a shellscript to start the javaprogram and to check out the program already runs.
    here a little script to start
    #=====================================
    CLASSPATH=**your CLASSPATH**
    JAVA_HOME=**your JAVA_HOME**
    PATH=$PATH:$JAVA_HOME/bin
    **your environment**
    export CLASSPATH JAVA_HOME PATH **your environment**
    #is the program running? (not the best solution but it should work ;-))
    a=`ps -ef | grep **your programm**`
    if [ "$a" == "" ]
    then
    nohup java **your program** 1>**your logfile** 2>&1
    fi
    #=====================================
    the crontab entry:
    */10 * * * * your program
    the 5 starts mean:
    minute,hour, day,month,day of week -> look at the man page (man 5 crontab)
    to edit the crontab use the command crontab -e under the useraccount where the program should run.
    to write a startscript (rc-Script) you can look at the skeleton-file. normaly it is in /etc/rc.d. name skeleton.
    copy that file and edit it. after that link the file to the runlevel-directory.
    hope it helps
    carsten

  • Auto-Run Code on OC4J start

    Hi,
    Is is possible to Auto-Run a piece of code, either by
    calling a method on a Session bean or calling a Servlet,
    when OC4J is started up?
    Cheers,
    Ro

    Hi
    You can also use a servlet that implements ServletContextListener - this fires before the application server opens up for user requests. Great for loading lookup codes, etc....

  • How to set Lion built-in FTP Server auto run off

    Hello all.
    I set FTP Server by using Rumpus Server application.
    But Lion's built-in FTP Server is running on the front.
    So if I try to connect my FTP Server out of my LAN, I can only connect to the built-in FTP Server despite I wanted to connect Rumpus FTP Server.
    It can be solved by unload the built-in FTP Server(using sudo -s launchctl unload...) but every after rebooting I should set it because it is set to run automatically in every booting.
    How can I set the auto run off?

    well, the ftp server (=ftpd) takes account info from the user list for your mac. so, go to the system settings on your mac, then to users, and then just add another user with a password of your choice (tap on the little plus-sign to add a user!). this will then be a valid user for your ftp server after you restart your ftp server.
    the other thing you want to do, about the home directory, is called chroot. you can set the home directory of a specific ftp-user to be another directory then the standard. for this, there are configuration directives in the configuration file in /private/etc/ftpd.conf which you have to edit by hand. so make sure what you do there.
    you should read this before editing the file, this will give you a better understanding of what to put there: https://developer.apple.com/library/mac/documentation/darwin/reference/manpages/ man8/tnftpd.8.html

  • Job Schedule - Doesn't auto run at a given time.

    Hi
    I hope you can help. I have set up the job below:
    DECLARE
    X NUMBER;
    BEGIN
    [i] SYS.DBMS_JOB.SUBMIT
    ( job => X
    ,what => 'REPORTING_API_12_IR02;'
    ,next_date => to_date('13/02/2006 15:58:27','dd/mm/yyyy hh24:mi:ss')
    ,interval => 'TRUNC(SYSDATE+1)'
    ,no_parse => TRUE
    SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
    END;
    commit;
    It compiles and is viewable from dba_jobs, but for some reason doesn't seem to auto run at the times given.
    Can anyone help?
    Thanks.

    i tried to view that with:
    show parameter job_queue_processes
    and got the following error:
    SQL> show parameter job_queue_processes
    unknown SHOW option "parameter"
    unknown SHOW option beginning "job_queue_..."
    anything wrong with my statements?
    thanks again

  • SSRS 2008 R2 Report parameters have default values and report not to auto run

    Hi, I am using SSRS 2008 R2 one of my requirements for a Report is all the parameters have default value and I do not want this report to auto run when users open this report. I can create a dummy hidden parameter to break the auto run for this
    report. But I am looking for solutions other than that.
    Thanks in advance..........
    Ione

    Hi lone,
    According to your description, you have a report with parameters. Now you want you report not to run automatically with your parameters default values. Right?
    In Reporting Service, if you have parameters with default values in your report, your report will always auto run with these default values. We can say these default values are used for report running initially. So for your requirement, if you really need
    to see your default value before the report running, the best workaround is set one more parameter to break the auto run like you have done. If you just want your report not to auto run, your can achieve it by removing those default values.
    Reference:
    Report Parameters (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • How to run servlet codes in WebServer 6.1?

    I am new to Java Web Server and at our place we had installed WebServer 6.1. How to run Servlets in this - the default directory is
    http//win2000:81/Sun/WebServer6.1/docs
    I have'nt insatlled any new virtual class / servers - just running with the default class and servers.
    I could not find any virtual directory named servlet (similar to JavaWebServer 2.0) here.
    Someone kindly tell me how to post servlet files and run them.

    Refer "Sun ONE Web Server 6.1 Programmer's Guide to Web Applications"
    http://docs.sun.com/app/docs/doc/817-1833-10
    Meena

  • How to run servlet in java webserver2.0

    how to configure java webserver2.0 and how to run servlet in that

    Hi Friend,
    Try changing the servlet code to this and just tell wat happens after this.
    and wat can you see on your Browser Screen.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class login extends HttpServlet {
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    if (req.getParameter("t1") == null || req.getParameter("t2") == null)
    out.println("Enter User Name And Password");
    String uid=req.getParameter("t1");
    String pwd=req.getParameter("t2");
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println("<html>"); out.println("<head>");
    out.println("<title>Login</title>"); out.println("</head>");
    out.println("<body>");
    try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException e)
    out.println("<h3>"+e+"</h3>");
    try{
    Connection con=DriverManager.getConnection("jdbc:odbc:ms","scott","tiger");
    PreparedStatement psm=con.prepareStatement("select * from reg where uid1=? and pwd=?");
    psm.setString(1,uid);
    psm.setString(1,pwd);
    ResultSet rs=psm.executeQuery();
    if(rs.next())
    { out.println("<html><head><title>WELCOME</title></head>");
    out.println("<body><b><i>Hello user "+uid+"</b></i>");
    out.println("</body></html>"); }
    else
    res.sendRedirect("http://localhost:8080/login.html");
    } catch(SQLException e)
    { e.printStackTrace();}
    rs.close();
    con.close();
    out.close();
    After this try creating a odbc for oracle database at control panel with the name ms.
    Please inform me wat happens after this and friend do give some information about wat kind of web-server are you using.Because calling of your servlets differs the way your configure your web-server and the default configurations differ from web-server to web-server.
    Regards,
    RAHUL

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • Unable to run Servlet program using J2EE SDK

    Hello,
    i am a newbie to all this j2ee stuff and servlets even.so the problem that i have maybe a very common one and i hope that most of you may have a fix to it...
    i use J2EE SDK to compile and run Servlet programs.I have a Servlet program with the class name defined as
    public class MyServlet extends HttpServlet ....
    the file is stored as MyServlet.java
    i set the CLASSPATH variable so that the required classes for the compilation of the program can be located.
    the program compiles without any glitches.
    However when i run the program by saying
    java MyServlet
    ( i dont think its any different to run servlet code is it?)
    i get the message
    java.lang.NoClassDefFoundException:MyServlet
    Can someone suggest a remedy?
    thank you
    -NDK

    First, I don't understand what you are trying to do. Running a servlet ?
    Servlets are ran by an application server ! (Apache Tomcat ....).
    Second, is your class in any package ?

  • How to run servlet in weblogic 8.1

    hi!
    i m new to weblogic.how to run servlet in weblogic8.1.i get lot of errors when i compile it in command prompt.but when i do the same thing in tomcat,i dont get errors & it runs successfully.help me out.how to compile servlets in weblogic 8.1.some say i have to create .jar file.pls tell me the procedure.i m new to j2ee.i have installed jdk1.5 .
    pls its urgent

    a lot of error....
    mmmm no sorry, i don't see
    it remembers me when i was dating sarah,it was very difficult... but now i'm dating anne it's really easier... any idea on what was going wrong with sarah?
    ok sorry for this allegory, just tired to ask always the same thing:
    WHAT ERRORS???

  • How to Run servlet in Tomcat 5.5.9

    hi
    How to run servlet in tomcat 5.5.9?how to set context path in server.xml of conf folder in tomcat since there is no context tag in server.xml.
    Jiten

    Hi ! I have a similar problem, well, it's along the same line ...
    I'm using NetBeans 4.1, and i've coded a servlet. Using NetBeans to launch my servlet (with the bundled Tomcat 5.5.7) works fine, however i need to deploy my application unto a Tomcat 5.5.9 server.
    Thus, i copied the WAR file generated by NetBeans into the Tomcat 5.5.9 webapps directory, and Tomcat expands it.
    Problem is when i run my JSP pages with the form tags, they do not work on the Tomcat 5.5.9 environment. Anyone knows why?
    (These work on the NetBeans Tomcat bundle 5.5.7)
    My form action :
    <form name="index" method="get" action="PageServlet">
    My web.xml :
    <servlet>
    <servlet-name>PageServlet</servlet-name>
    <servlet-class>application.PageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>PageServlet</servlet-name>
    <url-pattern>/PageServlet</url-pattern>
    </servlet-mapping>
    I'm really stumbed on why it doesn't work in Tomcat 5.5.9, any help is greatly appreciated, thanks in advance ^_^

  • How to run Servlet in Tomcat 5.5.7 Server

    Hi,
    How to run Servlet in Tomcat 5.5.7 Server. I mean where I should copy my *.class file.
    Thanks in Advance.
    bbye.

    In order to complile the servlet you need to tell java where to find the servlet libary (as stated above by setting the class path). or (much easier IMO)
    copy the servlet-api.jar to
    JavaInstallDirectory\jre\lib\ext

  • How to run Servlet on Tomcat 4.0.1?

    OK. I've made a simple servlet and using Tomcat 4.0.1 on Windows ME. Tomcat's root directory is C:\jakarta-tomcat-4.0.1\webapps\ROOT. I copied folder with my servlet (java's class) in tomcat's root folder. When I try to run the dialog 'File Download' is showen. Why?
    Thanks.

    I have Tomcat 4.0. I am trying to run servlet but I could not manage it. I have put my class file in webapp/root/web-inif/classes/ I can not run my servlet... how can I manage this... what should I do more?
    the errors are :
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/Servlet1
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:484)
    root cause
    java.lang.NoClassDefFoundError: Servlet1 (wrong name: servlet/Servlet1)
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
         at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1643)
         at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:937)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1372)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1254)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:867)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:400)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:484)

Maybe you are looking for

  • Firefox crashes upon start with the error message: Firefox had a problem and crashed. We'll try to restore your tabs and windows when it restarts.

    I have tried to open firefox multipul times only to receive the error message: We're Sorry Firefox had a problem and crashed. We'll try to restore your tabs and windows when it restarts. To help us diagnose and fix the problem, you can send us a cras

  • Is it possible to have an anchored object linked to a paragraph style?

    I want to link an anchored object to a paragraph style, so that whenever a paragraph that has a particular style is created, an anchored object is created at the same time. The particular application is to label the associate text with the anchored o

  • Partial Period Parameter Error

    Dear all, I had created new daily work schedule, period work schedule, define valuation classes, set work schedule rules and generate work schedule. After creation of this new work schedule rule, I assign it to an employee infotype 0007 Planned worki

  • BufferedReader and new line character

    Hi, Java doc of BufferedReaders' readLine method says Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. And the returned str

  • New Sleep Wake Issue

    Hey there MacBook owners. I seem to have a new issue with my MacBook not coming alive after I shut the lid and putting it to rest for the evening. I leave the computer asleep, rather than do a complete shutdown. But this morning when I was ready to g