#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Liverpool, UK
    Posts
    0
    Rep Power
    0

    Question


    I'm investigating JSP and servlets for a large project, and would like to know whether servlets can be scheduled to run automatically on the server?

    I would like to achieve similar fuctionality to Lotus Domino agents which can be scheduled to run at for example midnight, or every hour etc.

    Also can JSP fetch an external URLs raw HTML and assign it to a variable?

    Many thanks
    JohnnyJazz
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Jersey City, NJ
    Posts
    0
    Rep Power
    0

    Cool


    You could turn your servlet into a thread:-

    public class TimerServlet extends HttpServlet implements Runnable

    Then in the init you can set up your variables:-

    public void init(ServletConfig config) throws ServletException

    Then in the run method:-
    while( true ) { // run forever....
    try {
    theDate = new Date();
    // --------
    Calendar rightNow = Calendar.getInstance();
    int currentHour = rightNow.get(Calendar.HOUR_OF_DAY);
    int currentMinute = rightNow.get(Calendar.MINUTE);
    int currentDayOfWeek = rightNow.get(Calendar.DAY_OF_WEEK);
    if ((currentHour == previousRunHH) &&
    (currentMinute == previousRunMM)) {
    //
    Thread.sleep(2000); // try again in 2 seconds
    } else {
    code to do something
    }
    } catch (Exception e) {
    println(logPrefix() + ":run() Exception [" + e + "]");
    } // try()
    } // end while
    }

    // now you could just sleep fo an hour after adjusting to get to the first round hour...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Jersey City, NJ
    Posts
    0
    Rep Power
    0

    Cool


    Also forgot to mention you can specify Autoload in your application server, I use IBM WAS/VAJ and this loads your server which because it's now a thread will be initialized and you will now run....

    Not to sure about the URL though...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Jersey City, NJ
    Posts
    0
    Rep Power
    0

    Thumbs up


    I just noticed you are from Liverpool, Say hi to my mum, she lives in Stoneycroft, I left there over twenty years ago and ended up here.

    Peter.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Liverpool, UK
    Posts
    0
    Rep Power
    0
    Thanks for the reply Peter.

    Servlets/JSP is looking a real promising solution as it looks like it can accomodate all our requirements more efficiently.

    What would be advantageous is if you knew where i could download a complete programmers guide to using JSP/servlets which lists syntax, classes, code examples, etc, preferably in PDF format.

    I'll shout hi to your Mum - i'm in Tuebrook.

    Cheers
    JohnnyJazz
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Jersey City, NJ
    Posts
    0
    Rep Power
    0

    Cool


    We use servlet/Jsp's a lot, and I mean a lot, I have yet to come across anything we can not do (Internet wise) with this env. I like to think of a servlet as the TSR of java programming, as you get an enormous amount of support from the servlet environment.

    If you can spare some money, I know I did'nt have much in TueBrook, the O'Reilly books, and there is a servlet ver 2 book out now, are really good.


    www.sun.com is a good resource for documentation/samples.

    keep the faith...

IMN logo majestic logo threadwatch logo seochat tools logo