Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using java.util.Timer in JSP

Posted on 2002-03-20
4
Medium Priority
?
404 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I came across an unsolved Outlook issue and here is my solution.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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