Solved

using java.util.Timer in JSP

Posted on 2002-03-20
4
373 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
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 20 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
As a business owner, there are many things that keep you up at night. Profit margins, employee retention, human resource protocols, whether your product or service will remain competitive. When you own or manage a technology company that operates la…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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