Prevent simultaneous access on JSP

Prevent simultaneous access on JSP

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.

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.

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.

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.

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.

 

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright