Okay here is my question. I have a bean that is used from browser detection. Now I want to place it in the bean that controls order flow, and place it as close to the top as possible, and then redirect to the old browser page. Currently I have it on a JSP page.
[Bear edit: cleaned up title for easier reading] [ October 19, 2004: Message edited by: Bear Bibeault ]
Are you new to JSP? If so, I would urge you to reconsider your approach. It sounds like you are placing a lot of processing directly on the JSP pages. Current conventional wisdom is to avoid that at all costs and to place such processing in servlet controllers that perform all processing and then forward to the JSP pages to render the resulting page.
Look up terms such as "MVC" and "Model 2" in relation to web applications for more information about this pattern.
Might as well start off on the right foot and not develop practices that you will have to unlearn later.
I have an order servlet that "controls" the ordering process. I wanted to restrict users with certain browsers from getting into the ordering process, so I created a detect bservlet, really my first servlet. I placed the jsp tag for the servlet on several pages and the logic to say if certain browser redirect to hear. however I thought if I could include the servlet in the beginning of the ordering servlet then I wouldnt have to do it on each and every page. however I am new and not sure how to do this properly.
Still unclear about what you mean by "I placed the jsp tag for the servlet on several pages", but regardless, rahul is on-the-money with recommending a Filter to perform this kind of pre-processing.
You define the Filter to be invoked for certain URL patterns (perhaps all), and it gains control before the specified resource. It can make whatever check you wish and continue to process the resource or forward to elsewhere.
Again, putting a lot of goo on the pages that has nothing to do with rendering the view is something to be avoided.
OK, the reason that was confusing is because that is instantiating a bean, not a servlet. Very different animals.
In any case, that's an example of an anti-pattern you want to try to avoid -- instantiting a bean on a page to perform processing that is better handled by a controller servlet that gains control long before any JSP page gets invoked.
But in your case, since you want to invoke some pre-processing before every page (rather than performing pre-processing specific to a single page), the Filter approach is your best bet.
Joined: Mar 06, 2002
Will do. Thanks, where I was getting my information was using Bean and Servlet interchangabily.
Where can I find out about Filters?
rahul V kumar
Joined: May 20, 2003
I would suggest you read some information on jsp page assembly. You can find some examples of at J2EE blue print. By having run all your jsp pages through a common template would help resolve these kind of issues.