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
posted
0
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
posted
0
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
posted
0
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
posted
0
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 ?
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
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.