?
Solved

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

Posted on 2012-12-24
10
Medium Priority
?
2,265 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 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