Solved

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

Posted on 2012-12-24
10
1,797 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
10 Comments
 
LVL 24

Accepted Solution

by:
Tomas Helgi Johannsson earned 334 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 24

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 334 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 24

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 166 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now