This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi All, I am facing a complex situation in which I would like to have your advice. I am programming a web application where the situation is while processing I need to get user inputs i.e I perform some actions and prompt the user for further processing.Depending on user input I continue with the process transfer control to some other method or stop processing.I cant transfer control again and again between my JSPS and servlets as at the begining of the process I retrieve lots of data and store them in objects also there r many methods to be executed so it would require maintaining many flags and doing the situation accordingly. There can be two solns for this Either use applets for user prompting Use Threads. Prob with applets is that they may not run on all platforms and platform independence is our main issue. With threading it can be done as follows. The execution will begin in a thread.We will maintain an object in session which both the JSP as well as the Thread will access. Thread will do some processing and wait whenever it requires user inputs.At the user side the JSP will be continuously refreshing taking the object from session and will display dialog boxes whenever reqd , update the session object and wake the thread.This way the purpose can be achieved. I am not very sure if there is a better way of solving this problem So I would like to have ur advice on this. Thanks
Basically, you've got a design problem. Your web application is no more complex than anyone else's, and all these problems have been solved nicely already -- you just need to learn how it's done.
Very briefly, JSPs and Servlets have a Context available to them in which they can store objects. Take all your logic out of the JSPs, and put it into plain old Java objects (POJOs) and store these objects in the session context. Use the JSPs only for presenting the GUI. The POJOs retain their state in between calls.
I'm moving this to the JSP forum where there will be plenty of folks to back me up -- this really has nothing to do with Threads.
If your application cannot be achieved using existing servlet/JSP technology and established best-practice patterns which are layered upon the request/response cycle of the HTTP protocol, perhaps it is not the appropriate technology for the application. You might need to consider a fat-client, network-enabled Swing application.
I'd suggest reading up on web application architecture before diving off into weird solutions like trying to thread a web app. [ June 03, 2004: Message edited by: Bear Bibeault ]
Keep in mind that under J2EE 1.4 you won't be able to start a thread in a JSP/servlet (so long as the container complies to the spec, anyway). The right way to do this is to use a Message Driven Bean (MDB). See the following article--right here on the ranch, by our pardner Kyle Brown.