| Author |
Servlet Only Fires Once
|
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
|
If I use jQuery.getJSON to call a servlet say with a button click to get some remote value, clicking the button will not fire the servlet again unless I change the parameter values sent to it. Why is this and can it be fixed?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
How have you determined that the servlet is only getting called once? Does the servlet exhibit the same behavior when you invoke it directly from the browser? It sounds as if this might be a browser caching issue. [ November 27, 2007: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
To verify the only once calling I put a System.out.println("test") This is the only code in the servlet(for testing) in the doGet method. It only writes once if the parameters do not change. If I start the app navigate to the calling page then manually call the servlet directly(type in address) the System.out.println("test") prints every time I press enter key.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
|
You might want to add nocache headers to your response (see Servlets FAQ) and see if that makes a difference. The fact that the change in param value triggers a hit makes this sounds suspiciously like a caching issue.
|
 |
Hongli Li
Ranch Hand
Joined: Oct 29, 2006
Posts: 124
|
|
one way to do it is, in Jquery Ajax call, you can specify no cache a hack is add a variable to the url with a constantly changed value like: String url = requestUrl + "?now=" + new Date(); when you call jquery to make an ajax call, if the url is not changed, you will get the same result. [ November 30, 2007: Message edited by: Hongli Li ]
|
Do you know why this cup is useful? Because it is empty.
|
 |
 |
|
|
subject: Servlet Only Fires Once
|
|
|