Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to update the contents of a jsp page from another jsp

 
smee bond
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three jsp pages, namely: parent.jsp, table.jsp and create_entry.jsp.
- "Create_entry.jsp" is a form used to get the user info and create new rows in the database with this information.
- "table.jsp" is used to retrieve the data from the db and display as a table.
- "Parent.jsp" includes "table.jsp" as <jsp:include page="table.jsp" /> so that the table is displayed as a section in parent.jsp

My problem is whenever a new row is inserted in the db, the Parent.jsp is not updated with the new row until I hit refresh. So, whenever I create a new entry in db, how do I update the table in Parent.jsp? Please help. Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are these JSPs related? Or are you talking about automatically refreshing the page when someone somewhere else updates the db?
 
smee bond
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Parent.jsp has a link to create new user entry. on other hand, parent.jsp also has a table (from table.jsp) that displays all the existing entries from the db (for eg: name, address, telephone no).
> When you click on link to create new user entry in parent.jsp, it opens the form (create_entry.jsp) where user enters the info and clicks Submit. On submission, the data is updated in the db as a new row. Apart from the db being updated, I also want the table in parent.jsp to be updated dynamically (without hitting "refresh").

As of now, the new entry is not seen in parent.jsp until I hit "refresh".

yes, I meant dynamic refresh of parent.jsp when the db is updated.

[ December 07, 2007: Message edited by: smee bond ]
[ December 07, 2007: Message edited by: smee bond ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you opening Create_entry.jsp? I'm assuming that your form action=create_entry.jsp right? If that is the case you will probably have to reload the Parent JSP since you are redirecting away from it. You could just make the action=Parent.jsp on your Create_Entry.jsp form and then it will reload the parent and you will get your new table row.

How are you loading the table in your parent jsp to begin with?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing can cause the page to automatically refresh when the DB is changed asynchronously. You'll either need to refresh the page manually, or cause it to refresh itself at intervals to poll for changes.
 
smee bond
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> parent.jsp has <jsp:include page="table.jsp" />
> table.jsp has <a href="create_entry.jsp" />
> and create_entry.jsp has <form action="make_entry.jsp" method="post" onsubmit="return checkEntry();">
{we can ignore checkEntry(); as it just checks for empty fields and warns the user to enter data}

> now make_entry.jsp just calls a EntryUtil Bean to update the db.
(All these are existing code)
Hope this is clear. Please guide me on this
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to just have the last action refresh your Parent.jsp on submit. That will be the slickest way to do it. You know you are updating the db so just redirect back to Parent.jsp. This will reload the page, then you will get your new table with updated data.

How are you loading the table itself? From a bean? Directly out of a sql result set? Are you using Servlets?
 
smee bond
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using response.sendRedirect(parentURL) in make_entry.jsp, but the problem is, the form window (pop-up) itself is being redirected to parentURL. Instead I want to close the popup window and refresh the parent window.

I have found a solution now. I am refreshing the parent window using javascript as follows in make_entry.jsp (popup window):

window.opener.location.href = parentURL;
window.close();

this is working perfectly fine for me. I read somewhere that I could also use window.opener.location.reload(true); But this does a hard reload.

Thanks for all your advice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic