Solved

using java.util.Timer in JSP

Posted on 2002-03-20
4
366 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
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

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

Author Comment

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

Expert Comment

by:kotan
Comment Utility
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 20 total points
Comment Utility
> 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now