Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Updatable DataGrid: JSP  RSS feed

 
Priya Babu
Greenhorn
Posts: 7
Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a java web application which resembles a blog post wherein multiple users can post their comments or remarks simultaneously.

If someone posts a comment, immediately that comment should be made available for view to others without having to do page refresh from their browsers.

Please let me know how can this be achieved in JSP ?

 
Prexa Shah
Greenhorn
Posts: 9
Eclipse IDE Java jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,

Ajax will be the best solution for this problem.Try using it.

-Prexa.
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can achieve this using Ajax, client will be able to commuincate with server without refreshing the page.. If you would like to learn it, try it in w3schools.
 
Priya Babu
Greenhorn
Posts: 7
Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepak & Prexa,

Thank you.

I tried developing a simple example that updates a list of employees to the web page using Ajax. The page refreshes up the data as and when a new employee is added to the database. I used Ajax, JSP, & JavaScript Timer.

My question is both in my sample as well as the real application, we need to retrieve data from database. Thus, calling up to the server each time (based on some time interval, I set 3 seconds here), may result in both network & database trafficking.

Note: I am using connection pooling mechanism for Java-DB connection. I tested my example on my local Tomcat server.

I want to check if there are some other optimized solution available or if my above method itself can be optimized in some way?

Is it possible to provide some notification to the Java application as and when a record gets added to the database table.

Adding to this, I need a solution that is compatible to all browsers. Is the above solution, I described, cross-browser compatible.

Please give me a helping hand.

Thanks in advance.



 
Prexa Shah
Greenhorn
Posts: 9
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sathiya Priya wrote:

I tried developing a simple example that updates a list of employees to the web page using Ajax. The page refreshes up the data as and when a new employee is added to the database. I used Ajax, JSP, & JavaScript Timer.

My question is both in my sample as well as the real application, we need to retrieve data from database. Thus, calling up to the server each time (based on some time interval, I set 3 seconds here), may result in both network & database trafficking.



Hey, kindly provide some example code(if possible) so that i can have better idea about your question...

-Prexa Shah
 
Priya Babu
Greenhorn
Posts: 7
Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prexa,

My ultimate question is this:

1. Can we track the CRUD operations on DB from Java application via any notification mechanism?



 
Swastik Dey
Rancher
Posts: 1787
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database are you using? Probably oracle has got this kind of a feature.

http://download.oracle.com/docs/cd/E14072_01/java.112/e10589/dbchgnf.htm#CHDCJFGJ
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is no. You page must poll the server using Ajax. There is no way to notify a page sitting on someone's browser somewhere on the Internet that the database has changed. How would you even know who's got the page loaded into their browser?
 
Priya Babu
Greenhorn
Posts: 7
Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Thanks for your replies.

With Ajax, I am able to achieve this.

My work flow goes like this:

The page callserver.jsp contains a javascript that is set with a timer that calls the page output.jsp by making asynchronous request thro' AJAX. The output.jsp actually retrieves the list of records from DB and the response of output.jsp is produced on callserver.jsp with the request being passed every 3 seconds.

As I mentioned, I have used connection pooling and stored the list variable in a session that gets updated with new changes on every request.

I just would like to confirm if any other better solution is available that I got clarified from Bear's reply as no.

The DB to be used is MySQL in this case and no way of changing this.

Thanks once again for helping me out.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!