• 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

"jsp:include page" and refresh

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used <jsp:include page=....> hoping that it dynamically picks the new file content. However, I found I need to hit "refresh" button to get it. Is it because it uses some cached page ? How to make it dynamically load the latest page content instead of loading any cached results ?
Thanks.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The <jsp:include .../> tag is a runtime include (vs the include directive which is compiled into the servlet that the JSP becomes) so you're correct that it is "dynamic." The JSP itself however, is compiled into a servlet and that servlet is stored by the Web Container (in tomcat its usually $TOMCAT_HOME/work/...). It isn't until another request is made for that JSP page, that any new dynamic content will be displayed because the <jsp:include../> tag is processed by the web container when the page is translated at the time of the request. So, in short, the page first needs to be translated in order to display its dynamic content and that translation doesn't happen until the page is requested. If you want the page to refresh after some action, you can handle it via the a servlet or perhaps some javascript. It depends on how the page itself is requested (through a servlet, or a hyperlink etc..) and what action causes that file content to change.
Hope this rudimentary explanation makes sense.
[ August 27, 2003: Message edited by: Brian R. Wainwright ]
 
Steve Yu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand what you said. What I did is I use a servlet and this servlet "forward" to this JSP. So in my http request's URL, I call this servlet. However, after I modified the content (same file name) of the file in that <jsp:include page ="file" />, I sstill see the old file content when I enter the same URL. I have to click "Refresh" to see the new content. How to deal with it ?
 
Brian R. Wainwright
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmmm.... I think I see the problem - if you're using RequestDispatcher forward(request, response) it will forward the current request on to another resource - in this case the problematic JSP. Fine, but it keeps the current request and response objects which may be what's causing the problem. Try using reponse.sendRedirect() in your servlet instead, which creates a whole new request for the resource.
As an afterthought, encode the URL to your JSP as well -
response.sendRedirect(response.encodeURL("theURLTotheJSP"));
[ August 27, 2003: Message edited by: Brian R. Wainwright ]
 
Steve Yu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian R. Wainwright:
hmmmm.... I think I see the problem - if you're using RequestDispatcher forward(request, response) it will forward the current request on to another resource - in this case the problematic JSP. Fine, but it keeps the current request and response objects which may be what's causing the problem. Try using reponse.sendRedirect() in your servlet instead, which creates a whole new request for the resource.
As an afterthought, encode the URL to your JSP as well -
response.sendRedirect(response.encodeURL("theURLTotheJSP"));
[ August 27, 2003: Message edited by: Brian R. Wainwright ]



well, I need to keep those objects that were set in the "setAttribute", if I will sendRedirect it is just a plain redirect without transfering those objects that I need. Right ?
 
Sheriff
Posts: 67747
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

sendRedirect it is just a plain redirect without transfering those objects that I need. Right ?


Correct. A redirect will cause a new request to be generated by the browser, so any request attributes will not be available to the new request.
My suggestion would be to search this forum, along with the Servlets and the HTML/Javascript forums, for 'cache' and 'caching' for techniques to avoid having your pages cached.
hth,
bear
 
Steve Yu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it was because I viewed the page first before it was modified and I used the same browser window. Now I repeat the scenario but view it from a new browser window it is fine. So, thanks anyway.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.. Could you please describe how dis you solved this problem? i am facing the same issue, jsp:include is displaying the earlier version of html page that is being created dynamically and if i am deleting the page which is to be included, the even though it will be created in run time, but this jsp:include is not picking up that new page. I am stuck in this.
 
Bear Bibeault
Sheriff
Posts: 67747
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
This post was made 12 years ago and much has changed in the web world since then. I would suggest that a JSP include is no longer the best way to set dynamic content in a page, You should be using JavaScript and Ajax to update only the part of the page (or displayed data) that has changed.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic