Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"jsp:include page" and refresh  RSS feed

 
Steve Yu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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.
 
Brian R. Wainwright
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
niks pan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!