[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error while using Timer

Posted on 2009-04-30
8
Medium Priority
?
256 Views
Last Modified: 2013-11-23
Hi,

I am trying to create a code that will send some data from the server side and refresh the JSP automatically each 5 second.  I am using Timer to do this (not sure is this is a good idea) and I have following error:

Exception in thread "Timer-0" java.lang.NullPointerException
      at org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
      
Tracker genTrac = new Tracker() ; 
genTrac.getPosition( request.getParameter("id")) ;
		
int numberOfMillisecondsInTheFuture = 3000;//10000; // 10 sec
 Date timeToRun = new Date(System.currentTimeMillis()+numberOfMillisecondsInTheFuture);
Timer timer = new Timer();
 timer.schedule(new Position(genTrac,request,response), timeToRun);
----------
public class Position extends TimerTask{
 
	
	public Position(Tracker t, HttpServletRequest request,HttpServletResponse response) {
		
		this.request=request;
		this.response=response;
		this.t= t;
	}
	Tracker t;
	HttpServletRequest request;
	HttpServletResponse response;
	
	@Override
	public void run() {
		t.simulateMovement(Double.valueOf(t.getLognitude()),Double.valueOf(t.getLatitude()));
		request.setAttribute("tracker", t);
		 RequestDispatcher rd= request.getRequestDispatcher("/position.jsp");
		 try {
			rd.forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
 
}

Open in new window

0
Comment
Question by:Lucinda08
  • 4
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24275093
you can't do that. The request is no longer valid once you have returned the response.
you need to implement the refresh in your html

0
 

Author Comment

by:Lucinda08
ID: 24275130
How to do that? I need to pass data from server side.
0
 
LVL 92

Expert Comment

by:objects
ID: 24275189
you can't send data from server side. the browser needs to reload to pull data from server.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Lucinda08
ID: 24275253
So what should I do? Is there any way to automatically refresh browser and pass data?
0
 
LVL 92

Expert Comment

by:objects
ID: 24275355
you would have browser do an auto refresh which would send a *new* request to the server which the server could handle

0
 

Author Comment

by:Lucinda08
ID: 24275482
Can you give me step by step guide on how to do this.
0
 
LVL 92

Accepted Solution

by:
objects earned 750 total points
ID: 24275749
you can use ameta tag, for example to load my.html after 10 seconds u would add




0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 750 total points
ID: 24277108
That's about the most common Ajax pattern, which you can use:


ajaxpatterns.org/Periodic_Refresh
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

831 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