?
Solved

using java.util.Timer in JSP

Posted on 2002-03-20
4
Medium Priority
?
385 Views
Last Modified: 2010-04-01
im using JDK 1.4

my code is :

<%@ page import="javax.telephony.*" %>
<%@ page import="java.util.Timer" %>
<%@ page import="java.util.TimerTask" %>
<%@ page import="Callback" %>
<%!
     class CounterTimerTask extends java.util.TimerTask {
        /**
        * Date format used in message.  Includes milliseconds.
        */

        public static final SimpleDateFormat FMT = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS aa");

        private String name;
        private Date sked;
        private Callback cb;

        public CounterTimerTask(String name, Date sked, Callback cb) {
           this.name = name;
           this.sked = sked;
           this.cb = cb;
        }

        public void run() {
           System.out.println("Starting " + name);
           System.out.println(FMT.format(sked) + " Thread " + name);

          try {
              cb.connect();
          } catch (Exception ex) {
              System.out.println("ERROR: " + ex.getMessage());
              return;
          }

          while(!cb.isDone()) {
              try {
                  Thread.sleep(500);
              } catch(Exception ex) {}
          }

          //cancel();

        }
     }
%>
<%
     Callback c = new Callback();
     c.setFirstLeg(request.getParameter("firstleg"));
     c.setSecondLeg(request.getParameter("secondleg"));
     String dateStr = request.getParameter("date");
     String timeStr = request.getParameter("time");

     java.text.SimpleDateFormat date_format = new java.text.SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
    Date sked = date_format.parse(dateStr + " " + timeStr);

     Timer timer = new Timer();
    TimerTask task = new CounterTimerTask("callback");
    timer.schedule(task, sked);
%>
<BR>
Result: <%=c.getLastError()==null?"Callback Complete":c.getLastError()%>
<BR>
<A HREF="index.html">Back</A>


------
its giving me :

Exception :

javax.servlet.ServletException: sun/tools/javac/Main
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:484)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

---

root cause

java.lang.NoClassDefFoundError: sun/tools/javac/Main
     at org.apache.jasper.compiler.SunJavaCompiler.compile(SunJavaCompiler.java:128)
     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:271)

---------


does this mean i cant use java.util.Timer() in JSP?
0
Comment
Question by:ibo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:ibo
ID: 6884771
i dont have any points right now :P credit?
0
 
LVL 3

Author Comment

by:ibo
ID: 6884778
btw since i didnt put interval (for multiple repetitions), i dont need to call cancel() right?
0
 
LVL 6

Expert Comment

by:kotan
ID: 6914694
This error is because of the server couldn't find tools.jar.
You need to have tools.jar in your classpath.
The tools.jar is located in {jdk path}/lib/
0
 
LVL 6

Accepted Solution

by:
kotan earned 60 total points
ID: 6914706
> btw since i didnt put interval (for multiple repetitions), i dont need to call cancel() right?
You're right. It only get execution one time.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
Introducing Priority Question, our latest feature.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question