Solved

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

Posted on 2012-12-24
10
2,137 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 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 25

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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

717 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