Sandra, relax.
The token that I am referring to is a general concept; don't take
then name "token" so literally. Like I said before, it represents a Java
object,
any Java object, which encapsulates information which you wish to
convey to your application about what happened during initialization.
It, the "token", could be as simple an Exception object placed in the
ServletContext
under a known key name. On each request, your controller looks for that
object under the known key name. If it exists, then you can forward to
a general error page, else your application knows that it was initialized
successfully and it can proceed.
If you want a more details about what happened, perhaps your "token" could
could wrap the exception along with some additional information, such as
a status code.
public class ApplicationInitializationInfo {
public static final String KEY =
ApplicationInitializationInfo.class.getName() + ".key";
public static final int MASSIVE_PROBLEM_CODE = 1;
public static final int WARNING_CODE = 2;
private Throwable exception;
private int statusCode;
public Throwable getException() { return this.exception;}
public void setException(Throwable t) { this.exception = t;}
public int getStatusCode() { return this.statusCode;}
public void setStatusCode(int code) {this.statusCode = code;}
}
In the ServletContextListener:
public void contextInitialized(ServletContextEvent sce) {
try {
// initialize stuff here
} catch {Throwable t) {
// Uh oh, an error occurred
ApplicationInitializationInfo info = new
ApplicationInitializationInfo();
info.setException(t);
info.setStatusCode(ApplicationInitializationInfo.MASSIVE_ERROR_CODE);
// Let the rest of the application know what
// the heck is going on so it can act appropriately.
sce.getServletContext.setAttribute(ApplicationInitializationInfo.KEY,
info);
}
}
HTH,
robert
> -----Original Message-----
> From: Heligon Sandra [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 06, 2003 11:12 AM
> To: 'Struts Users Mailing List'
> Subject: RE: Application Startup
>
>
> Sorry if my question is simple but I am new to Java and Struts,
> the Token object about which you speak is different from the Struts
> transaction token feature
> (that we find in the Action class generateToken(),
> isValidToken(),saveToken()).
> I have never used Token with Java simple application and Token
> with Struts,
> so I don't know if there is a difference. Or if "token" defines a general
> concept and not a specific object/feature.
>
> That's why if someone as an example of token-error object with
> ServletContextListener
> or HttpSessionListener, I am really very very interested thanks a lot in
> advance.
>
> Sandra
>
>
> -----Original Message-----
> From: Robert Taylor [mailto:[EMAIL PROTECTED]]
> Sent: 06 February 2003 16:07
> To: Struts Users Mailing List
> Subject: RE: Application Startup
>
>
> A token would be any Java object which you create to contain error or
> status information and place in ServletContext.
>
> robert
>
>
>
> > -----Original Message-----
> > From: Heligon Sandra [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, February 06, 2003 9:49 AM
> > To: 'Struts Users Mailing List'
> > Subject: RE: Application Startup
> >
> >
> > I don't know that we can use token to do this
> > do you have an example, please ?
> >
> > -----Original Message-----
> > From: Robert Taylor [mailto:[EMAIL PROTECTED]]
> > Sent: 06 February 2003 15:43
> > To: Struts Users Mailing List
> > Subject: RE: Application Startup
> >
> >
> > If there is an error, place a token in the ServletContext and have your
> > controller check for that token.
> > The token can contain error or status information.
> >
> > robert
> >
> > > -----Original Message-----
> > > From: Heligon Sandra [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, February 06, 2003 9:02 AM
> > > To: 'Struts Users Mailing List'
> > > Subject: RE: Application Startup
> > >
> > >
> > > The problem with the ServletContextListener is that we can not
> > > display error to the client if an error occur, isn'it ?
> > >
> > >
> > > -----Original Message-----
> > > From: Robert Taylor [mailto:[EMAIL PROTECTED]]
> > > Sent: 06 February 2003 14:35
> > > To: Struts Users Mailing List
> > > Subject: RE: Application Startup
> > >
> > >
> > > Use a Servlet and designate it to load on start up, or if
> > Servlet2.3 spec,
> > > look a ServletContextListener.
> > >
> > > robert
> > >
> > > > -----Original Message-----
> > > > From: Tarek M. Nabil [mailto:[EMAIL PROTECTED]]
> > > > Sent: Thursday, February 06, 2003 8:14 AM
> > > > To: Struts (E-mail)
> > > > Subject: Application Startup
> > > >
> > > >
> > > > Hi everyone,
> > > >
> > > > I'm using Struts 1.0.2.
> > > >
> > > > I need to do some stuff on application startup. I consulted the
> > > > documentation, and noticed that there's support for such a thing
> > > > in Struts 1.1. No mention of it in 1.0.2, though.
> > > >
> > > > Is there a way I can do some action on application startup in
> > > > Struts 1.0.2.
> > > >
> > > > Please advise,
> > > >
> > > > Thanks,
> > > >
> > > > Tarek M. Nabil
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]