?
Solved

Update JSP/HTML page when DB insert/update/delete occur

Posted on 2012-12-24
10
Medium Priority
?
2,563 Views
Last Modified: 2015-01-05
Hi,

I have a website developed using java/servlets. This site gets input from user.

And, now when an administrator logs in, I want to get the live user names printed on admin page when a new user gets added.

Typically, I would like to update the content of my HTML/JSP page without refreshing when a DB INSERT/UPDATE/DELETE occurs.

Can anyone help me to achieve this using Java/Servlets? if not please provide me an alternate solution.

Thanks
0
Comment
Question by:arjunarajan
  • 4
  • 3
8 Comments
 
LVL 26

Accepted Solution

by:
Tomas Helgi Johannsson earned 1336 total points
ID: 38720373
0
 

Author Comment

by:arjunarajan
ID: 38722985
Hi,

The above references gives me to get the data using AJAX. But, what I am looking for is that my page needs to be updated with the latest added users while the administrator is logged in and is in any of the page with admin rights.

Will be having a <DIV> to display the details of the newly added users.

I want this DIV to be updated whenever a new user is added or existing user update his details WITHOUT SENDING REQUEST TO SERVER explicitly.

Thanks.
0
 
LVL 26

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 1336 total points
ID: 38723014
Hi!

Every browser has its own session to interact with the server. And data between a session and server is isolated from other sessions for security purposes. To be able to retrieve data from other sessions it has either to be put into a database or you could use an Application Object to hold some data that may be visible to all/some sessions. Be careful what data you put there.
http://www.java2s.com/Code/Java/JSP/UsingtheApplicationObject.htm

To retrieve the data you will need to send a request to the server in some way either through a complete page refresh or AJAX where you can update part of the page as needed.

Regards,
    Tomas Helgi
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Comment

by:arjunarajan
ID: 38742641
Hi Tomas,

You mentioned to retrieve we need to send a request to server, I agree with you but my requirement is some thing similar to a page that refreshes automatically when an update to a value is done.

Something similar to a live cricket score update or a stock exchange webpage update where the latest will be updated without sending any request explicitly but the particular div/section  will be updated automatically,

Hope this gives u more idea on the requirement

Thanks
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 38742945
Hi!

Using AJAX you can update only a part of a page e.g. div section where the page or event in the page sends request to the server and updates only the desired section of the page. For the end user is looks like the page is updated without him/her actually hitting a button/link/ page reload.

Regards,
    Tomas Helgi
0
 

Author Comment

by:arjunarajan
ID: 38742957
Can you pls provide a simple example with code snippet to achieve what I had asked for using AJAX.
0
 

Author Comment

by:arjunarajan
ID: 38761925
Can anyone provide me a solution or a way to achieve the requirement. Its urgent. I can give you double the points by creating another question and accept you solution immediately
0
 
LVL 1

Assisted Solution

by:rikaz
rikaz earned 664 total points
ID: 39568787
If your familiar with jQuery  ajax call its even easy. What you should do is after the db operation is success, you can send it via xml format or JSON send along with the response. And capture the required data from the ajax response and in jquery success method reconstruct your DIV and update the information.
http://api.jquery.com/jQuery.ajax/

jQuery Ajax Example With JSON Response
http://www.lennu.net/2012/06/25/jquery-ajax-example-with-json-response/
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question