?
Solved

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

Posted on 2012-12-24
10
Medium Priority
?
2,430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 25

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 25

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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 25

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

650 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