File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Reloading JSP page when there is any update in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Reloading JSP page when there is any update in the database" Watch "Reloading JSP page when there is any update in the database" New topic
Author

Reloading JSP page when there is any update in the database

Keerthi Chandhu
Greenhorn

Joined: Feb 03, 2009
Posts: 16
Hi,

Can anyone please suggest me how to reload a JSP page when user updates any value in the database from the screen?

Actually when user changes any value in the JSP it is being updated in the database but it is not giving the updated value in the JSP until user manually Refresh the page.

Thank you.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Sounds like the common caching issue. Please see the JSP FAQ on this issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Try doing this.

<% response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
%>


Hope it works


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
ujjwal soni wrote:
<% response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
%>

1) Scriptlets always indicate a bad practice.
2) Code duplication is always a bad practice.
3) You're overriding the correct Cache-Control header with an incorrect one.
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Thanks for your suggestion...

Prevent caching of JSP output

Put following scriptlet at the beginning of the JSP to prevent output caching


Keerthi Chandhu
Greenhorn

Joined: Feb 03, 2009
Posts: 16
Hi Ujjwal soni ,

Thank you so much for the reply.

I tried making cache control

but it is not updating with the updated value utill I click refresh manually.

Actually to decrease number of queries to database, I am passing database values as parameters to another jsp and while displaying I am getting those parameters using


when I update this value, it is getting updated in database but it is not displaying the updated value until I click refresh manually.
Would appreciate your help.

Thank you,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

ujjwal soni wrote:Put following scriptlet at the beginning of the JSP to prevent output caching

As previously pointed out, scriptlets are a poor practice. This should either be done in the page controller, or better yet, in a filter.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
ujjwal soni wrote:Hi,

Thanks for your suggestion...

You're good at Googling. Why don't you explain the topicstarter how to do it so that s/he can learn from it? Why don't you mention the source of this information?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reloading JSP page when there is any update in the database