• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prevent simultaneous access on JSP

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have one jsp page that i use to drill down the report. Challenge is if any user running that report, if other user trying to access that page, it should be prevent. Means at one time only one user should be able to access that page & when he close the window other should be accessible that jsp page.

Thanks.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
place your code which need to be prevented from access buy second person in a synchronization block . It ensures that no two threads can access the same code at once.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good design would notify the 2nd user with a "Busy, try again later message"

If this report generation takes longer than a couple of minutes you have a bad design - the HTTP request / response cycle should execute quickly.

Bill
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for response.

Actually what the issue is, i want to stop the request to access genReport.jsp if same jsp page is accessed by other user. Like if this jsp is opened on one user machine & other user logged on separate machine, it should be prevent to serve other user request (page should display alert or we can redirect to other page) & if first user close the window of that particular jsp. it should now will available to process other user request.

Thanks
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with William Brogden. Even though your requirement to lock the page can be fulfilled by some means that may not be a clean solution.From your use case you are trying to lock the page based on a session.Then you have to think about session timeout also.You can add HTTP Session Listener and track the usage of that particular page.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can implement this by using synchronize in java
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vivek dhiman wrote:Challenge is if any user running that report, if other user trying to access that page, it should be prevent.


Why is that? What's the problem with multiple users running a report simultaneously?

Web apps are inherently multi-threaded and multi-user. Instead of trying to prevent that, you should learn how to wrote web apps that can handle concurrency. And, of course, and reporting logic should not be part of the JSP, but instead in a servlet or a backing bean or a helper class.
 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what Ulf Dittmer told is the good practice you should follow. You need to block your part of businesss logic if one user is doing the action. I think you tried to block your jsp page because you have writtened the logic in the .jsp page itself in the scriptlet. If you done like so it is not good practice. Do in structured way and separate your view and logic. And you can do what you need in your your logic part by using synchronization not in your view page.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic