aspose file tools
The moose likes JSP and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark ""jsp:include page=..."  and refresh" Watch ""jsp:include page=..."  and refresh" New topic
Author

"jsp:include page=..." and refresh

Steve Yu
Ranch Hand

Joined: Mar 26, 2003
Posts: 60
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

Joined: Aug 12, 2003
Posts: 92
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

Joined: Mar 26, 2003
Posts: 60
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

Joined: Aug 12, 2003
Posts: 92
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

Joined: Mar 26, 2003
Posts: 60
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

Joined: Jan 10, 2002
Posts: 56222
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Steve Yu
Ranch Hand

Joined: Mar 26, 2003
Posts: 60
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "jsp:include page=..." and refresh
 
Similar Threads
Doubt in Final Mock Exam:HFSJ
Control cache in Servlet or..?
How can I solve this problem?!!!
Refresh page programatically
Is it possible to have a dynamic content value in Meta Refresh Tag