Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to refresh the jsp page when onload?

 
amanda wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my page display the contents in a database,
but each time it is loaded, it doesn't display the updated values in the database, only a 'refresh' makes it display the newly inserted records, what shall i do?
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should re-load that page...
Example I have A.jsp which will go the server to load some datas from database...
A.jsp
========
...
<form method="POST" action="A.jsp">
<input type="sumbit" value="Get Data" name="btnSubmit">
</form>
...
It's code to load new data from database and refresh your current page so your page will show the new datas
Correct me if i am wrong...
daniel
 
amanda wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my page actually reads data out from a database, display it, let user delete some data ,and then display the message in another page.
like a.jsp is my page for it,
then in the action field, i put message.jsp already, so what i want, is after click the submit button, both the message.jsp and a.jsp is called again..
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi amanda,
you could let a.jsp call itself.
In your code you do your db-operations first,
if( request.getParameter("btnSubmit") != null )
{
...db-oprarations
%>
<%=thenPrintYourMessage%>
<%
}
and then display your <form>
hth
cb
 
amanda wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks to you all. but can't the page load updated data from database onload without click button? like i just click a link and get a page displayed, and want the newly displayed page updated ...
I am so suprised all my page get form with data from database is not updated when the link just opened...
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like the browser is just displaying a cached copy of your page? If that is the case you can set some headers to prevent it from being cached:

I hope this helps...
Mark
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want your application to do that.. i think there are 2 options you can do...
1. You can add your jsp page with
<meta http-equiv="refresh" content="1000">
It will refresh the page every 1 minute..
2. You can use servlet class to get data from database... and within your jsp page you can use href link...
Example :
<a href="GetDataServlet">Get data</a>
correct me if i am wrong...
daniel
[ April 02, 2003: Message edited by: Fisher Daniel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic