You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Malcolm Ferguson <ma...@nkaos.com> on 2000/11/14 17:57:56 UTC
Architecture question: Beans and application-level resources
Hi all, I'm fairly new to Servlets/JSP/Struts and I'm trying to set up a
basic generic framework that I can use to build webapps on. The MVC pattern
makes a lot of sense to me and Struts seems to be a very well thought out
implementation, but I have a question regarding application architecture.
One of the great advantages of server-side java is that some resources can
be shared at the application level, as an example I have a servlet which
loads on startup and instantiates a connection pool class and stores it in
the application space. My question is: if I forward my requests to
non-servlet beans (through Action classes, in this case) for business-logic
processing, how can I make those application-level resources (or
Session-level resources) available to beans further on down the chain? Is
possible/advisable to pass a reference to the ServletContext down the line?
I am very interested to know what you think, and I would very much
appreciate any articles or tutorials which have examples of dealing with
this subject.
Cheers,
***********************************
Mac Ferguson,
Developer,
NKaos Interactive Media (http://www.nkaos.com),
579 Richmond Street West, Suite 400
Toronto, ON
M5V 1Y6
(Phone) (416)504.8931 x316
(Fax) (416)504.8472
***********************************
Architecture question: Beans and application-level resources
Posted by Lee Burgess <le...@red-bean.com>.
Malcolm Ferguson writes:
> Hi all, I'm fairly new to Servlets/JSP/Struts and I'm trying to set up a
> basic generic framework that I can use to build webapps on. The MVC pattern
> makes a lot of sense to me and Struts seems to be a very well thought out
> implementation, but I have a question regarding application architecture.
> One of the great advantages of server-side java is that some resources can
> be shared at the application level, as an example I have a servlet which
> loads on startup and instantiates a connection pool class and stores it in
> the application space. My question is: if I forward my requests to
> non-servlet beans (through Action classes, in this case) for business-logic
> processing, how can I make those application-level resources (or
> Session-level resources) available to beans further on down the chain? Is
> possible/advisable to pass a reference to the ServletContext down the line?
> I am very interested to know what you think, and I would very much
> appreciate any articles or tutorials which have examples of dealing with
> this subject.
>
According to the Struts User's Guide
(http://jakarta.apache.org/struts/users_guide.html) , you should get a
Connection object from your connection pool and pass *that* to your
business logic beans.
If you pass *any* servlet specific objects to your business logic
beans, you are tying those beans to your specific web application.
That kinda defeats the purpose of having business logic beans, since
you will no longer be able to (re)use that code in a non-web context.
So, yes, it is possible. No, it is not advisable. :)
Try not to think of forwarding your requests to your business logic
beans. That is counterintuitive.
Rather, think of calling your business logic beans from *inside* your
action beans. After all, you are manipulating business beans based on
a particular action (request); not manipulating a request based on
business beans. Though the result of the business bean manipulation
certainly determines how a response (ActionForward) is handled; that
is the responsibility of the action bean anyway.
Hope this helps.
--
Lee P. W. Burgess <<!>> Manipulate eternity. Power is a symphony:
Programmer <<!>> elaborate, enormous, essential.
Red Bean Software <<!>> Dream the moment with a fiddle in summer
lefty@red-bean.com <<!>> and a knife in winter.
Re: Architecture question: Beans and application-level resources
Posted by Bill Pfeiffer <ws...@tampabay.rr.com>.
I can think of 3 arhcitectual choices here:
1. Use the architecture set up for the action classes, which provides the
request, and get the ServletContext. If you've stored your connection pool
info here, you can get at it. Downside is, you mix you business logic with
your action classes knowledge of the ServletContext. This can be ok for
trivial app logic.
2. Obtain your connection in the action class and pass it into your
business objects (beans). Your business object need only know that it is
getting a connection, NOT where it came from. I think this approach is best
for larger scale apps. The action object talks to the business object at a
high level. Your business objects stay concerned with the business, not the
context.
3. Write your connection pooling as a singleton. Your business object can
then get at it directly via the class itself. Again your business object is
only aware of the business, but this is a little too close to a global
variable for me. Puts your business object into the business of being aware
of the singleton class(this is still a context, just not the same as a
ServletContext).
I'm sure there are more approaches; these are my initial thoughts based on
work I've done already.
HTH,
Bill Pfeiffer
----- Original Message -----
From: "Malcolm Ferguson" <ma...@nkaos.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, November 14, 2000 11:57 AM
Subject: Architecture question: Beans and application-level resources
> Hi all, I'm fairly new to Servlets/JSP/Struts and I'm trying to set up a
> basic generic framework that I can use to build webapps on. The MVC
pattern
> makes a lot of sense to me and Struts seems to be a very well thought out
> implementation, but I have a question regarding application architecture.
> One of the great advantages of server-side java is that some resources can
> be shared at the application level, as an example I have a servlet which
> loads on startup and instantiates a connection pool class and stores it in
> the application space. My question is: if I forward my requests to
> non-servlet beans (through Action classes, in this case) for
business-logic
> processing, how can I make those application-level resources (or
> Session-level resources) available to beans further on down the chain? Is
> possible/advisable to pass a reference to the ServletContext down the
line?
> I am very interested to know what you think, and I would very much
> appreciate any articles or tutorials which have examples of dealing with
> this subject.
>
> Cheers,
> ***********************************
> Mac Ferguson,
> Developer,
> NKaos Interactive Media (http://www.nkaos.com),
> 579 Richmond Street West, Suite 400
> Toronto, ON
> M5V 1Y6
> (Phone) (416)504.8931 x316
> (Fax) (416)504.8472
> ***********************************
>
>