• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making a Request to a Servlet More than Once

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp with an img tag whose src is set to request a servlet to display a chart. This is called from another jsp form where user can select various filters. The first time the request is made all works great. but if the user changes the filter settings and and makes the servlet request a second time the chart stays the same. I have verified the new filter values are being set but the servlet is only being called on the initial request.

at the head or called servlet I have(I also call a jquery empty on the div that holds the chart between requests. at the moment it just displays the former chart). It is like it is using cache:

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open the browser tools and observe the behavior of the Network tab. What's happening?
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Open the browser tools and observe the behavior of the Network tab. What's happening?



I looked at the output but not sure what to look for. I did see the servlet in question in the list the first time I made the request but not on subsequent request unless I close the parent form and reopen it.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then it is likely that whatever is responsible fro making the request may no be doing its job,. Usually even cached responses are shown in the panel.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Then it is likely that whatever is responsible fro making the request may no be doing its job,. Usually even cached responses are shown in the panel.



Every thing seems to be in order and fairly simple:

Controller calling jsp:



JSP:



Servlet:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not seeing anything there that should trigger a new servlet request.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Not seeing anything there that should trigger a new servlet request.



I have another form where filters for a remote sql call are selected then a request is made to the first section of code I posted(Controller).

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes that request?
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:What makes that request?



The last posted controller code makes a request to the following jsp which makes the request to the servlet in question.



Note: It almost has to be a cache issue because if I make a change to the img src line of code(which makes the request) to include a parameter that changes between requests it works great.

Example:

First request is
src="/QMSWebApp/CalibrationActivityChartServlet?unitcount=7"

Second request is
src="/QMSWebApp/CalibrationActivityChartServlet?unitcount=14"

In the original case, making request without a parameter, the browser seems to say the criteria posted to servlet has not changed so just display what is already posted.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are saying that when the JSP is displayed, a request to the image src is not made?

You could try the old trick of adding a random number as a request parameter just to see if it is indeed a caching issue.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:So you are saying that when the JSP is displayed, a request to the image src is not made?

You could try the old trick of adding a random number as a request parameter just to see if it is indeed a caching issue.



Is this random number generation something that I can do with JSTL?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... or JavaScript.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:... or JavaScript.



this works great:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, that should do it. Does it solve the issue?

If it does, you know you've got a caching issue. You can investigate why your caching directives aren't working (or leave the work-around, which is a bit grody, but no less used for all its grodiness).
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Yup, that should do it. Does it solve the issue?

If it does, you know you've got a caching issue. You can investigate why your caching directives aren't working (or leave the work-around, which is a bit grody, but no less used for all its grodiness).



Yes it solved the issue. But I have no idea where to start looking as to why caching directives are not working.

Thanks for your help on this today.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your caching directive only affects the page.
It does not affect the <img>'s that the page pulls back.

Here's an SO post that covers some techniques for forcing image reloads in a browser session.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Your caching directive only affects the page.
It does not affect the <img>'s that the page pulls back.


My assumption was that the caching directive were being placed on the image response. Steve, is that the case? If not, yeah.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, should have been a bit more expansive.
A no-cache that works for a page does not work for images, at least as far as a single browser session is concerned.
Hence the use of the random number thing, to fool the browser.
It only applies to <img> tags I think.

That SO link I gave does mention a header entry that can help.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You were understood. I just assumed (perhaps incorrectly) that the directives mentioned in the initial post were being placed on the image response. If they are on the page response, then yeah, they will have no affect on the caching of the image request.
 
reply
    Bookmark Topic Watch Topic
  • New Topic