Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Message between two servlet page  RSS feed

 
Prasad B Rao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement, I need to build a servlet page which take input of key in encoded format containing user id, access and page id. when two users enters the page second user should get a popup that another user is already in the page (I have stored the user already in a page in DB and when second user goes to the page I am able to retrieve from DB and show the message and make the page as read)
I am stuck at fulfilling below request
second user can request access upon which first user should get message to approve it. If the first user agrees then second user should get a message back to continue work and first user will get have the access as read and second should have access of write.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP doesn't work that way.

It's easy to use the DB as a place to store state, but immediate notification and handshaking is more difficult. You'll either need to poll from the pages, or limit your audience to modern browsers and use constant-connection technology. Either way, it's not an easy thing to set up.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad B Rao, Welcome to the Ranch!
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are not "programs". They are not continuously-running tasks. They are, in effect, "subroutines" that get called when a web URL request comes in and they are expected to process and exit as quickly as possible. The only time that 2 users would simultaneously be executing a servlet's code is if they had made simultaneous web requests, in which case they would each be running under separate temporarily-assigned threads.

What you are describing is a lot more complex than you realize - it's a workflow (business process) that requires the actions of 2 separate agents.

Such things are hardly unknown, but it's not something you get from some simple hand-waving "All You Have To Do Is..." process or brute-force stomping around in servlet code. At a bare minimum, you're probably going to need some sort of transaction management on your database, and there are entire frameworks and standards custom-designed for this kind of stuff when really serious workloads are required.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!