• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a bean inside another bean

 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new so please go easy

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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

You may be a beginner, but you're a JSP beginner, so off you go to the JSP forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didier, welcome to the Ranch.

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.
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay maybe I didnt phrase this correctly.

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.
 
rahul V kumar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if I understood your problem correctly. But I feel that Filters might help you resolve this issue.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:useBean id="db" class="com.dime.logic.DetectBrowser" scope="session">
<jsp:setProperty name="db" property="request" value="<%= request %>" />
</jsp:useBean>

<%
if(db.isns4() || db.isns6()) {
response.sendRedirect("/browser.jsp");
}
%>
[ October 19, 2004: Message edited by: Didier McGillis ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

This link should help you give an understanding about filters.
http://java.sun.com/blueprints/patterns/InterceptingFilter.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic