Hi,

thank a lot for your replies.

> 1) Initiating application objects,  you write at startup servlet and in it
> init method load all the objects you want in your application scope.  you
> only do this once for the life time of your application.

I agreed that you could initiate application objects in this way. That is
the best solution we could found.

> 2) Initiation session objects.  Since this is per user you can't do it in
> the startup servlet.  there is a lot of way to this.  One of them is to
> create an Abstract Action that extends from the Action class that have an
> abstract
> command method that all you action derive from it.  And all that you need
to
> implement in the perform method is call your precondition method that do
all
> the session stuff you wants.
>
> *** usually getting and creating object on your session or application
scope
> you write a helper class to do it ...

Yes, that was what I did now. It solves most cases but not all, e.g is my my
problem. Please take care again my matter. With this solution, the url that
we intend to visit must have action, however the url is so simple that we
could not find any reason why we have to assign an action for it except
initiating session objects if required, and the problem is whether there is
another way to move the session initation from abstract action to another
place. It wastes our time if we have number of this type of url.

e.g: we must define DoNothingAction that has only init methods for session
objects. Further it could be redunant if the session is already initiated
  <action  path="/test"
    type="com.action.DoNothingAction"
    scope="request">
<forward name="Success" path="/test.jsp" redirect="true"/>
  </action>

so I prefer this way:
  <action  path="/test" forward="test.jsp"/>

regards
Khang


> > -----Original Message-----
> > From: nguyen tuan khang [SMTP:[EMAIL PROTECTED]]
> > Sent: Thursday, May 16, 2002 7:18 PM
> > To: Struts Developers List
> > Subject: application and session initiation
> >
> > Hi all,
> >
> > Please help me the best solution for initiating application and session
> > objects in common projects.
> >
> > Assume
> >
> > 1. I have a jsp web page that use both session and application object of
> > session user. Meaning that the session and application objects must be
> > initiated somewhere before the user comes to this jsp page (!!!)
> >
> > test.jsp
> > ...
> > <jsp:usebean name="SessionObject" scope="session" class="..."/>
> > <jsp:usebean name="ApplicationObject" scope="application" class="..."/>
> > //user SessionObject and ApplicationObject here
> > ...
> >
> > 2. an URL test is mapped to test.jsp
> > meaning that when user browses localhost://project/test, the test.jsp is
> > invoked
> >
> > 3. the test URL does not need an Action, because there is no tasks for
it.
> >
> > my current solutions:
> >
> > 1. I have to create one Action for test URL, the Action is responsible
to
> > lookup these objects in Session and Application, if not found the action
> > initiats SessionObject and Application then put them in Session and
> > Context.
> > This is bad because:
> >     It is not worth creating Action like this (waste of time), and of
> > course
> > in project there is a lot of url like this so the same number of Actions
> > are
> > created in wasting because we are not sure which direct URL (like above)
> > user comes first (in order to put the initiation correctly) so we have
to
> > put the initiation as above in all Actions (sure that the next just need
> > to
> > lookup in Session and Context is enough), it means that the initiation
is
> > put in all actions but the really initiation is occured in only one
> > Action,
> > then the rest could lookup in Session and Context.
> >
> > 2. I use HttpSessionListener (Servlet 2.3), but I do not know why I
> > invalidate the session, the Listener's sessionCreate method is not
> > invoked,
> > it need restart web server.
> >
> > 3. I tried to override the init method in ActionServlet, but it is not
> > good
> > for both session and application objects initiation.The same as the
second
> > solution, sometimes the init method of ActionServlet is not invoked if I
> > call above URL (direct URL) it need restart web server
> >
> > Please help me show best solution
> > thank in advance
> > regards
> > Khang
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to