File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Session Start Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Session Start" Watch "Session Start" New topic

Session Start

Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
Is there any equivalence of global.asa of ASP in JSP?
Where can i write functions to be performed when:-
1)Application is started
2)Session is started
3)Session is stopped
4)Application is stopped

"A scientist is not person who gives right answers but a person who asks right questions"
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

2 and 3 can be managed using the javax.servlet.http.HttpServletListeners (Activation, binding etc)
1 and 4 are generally vendor specific. Generally you can register a class that gets started when the server starts, but how you do it and what that looks like changes between servers.
Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
Thnx, David for your help.
"A scientist is not a person who gives right answers but is a person who asks right questions."
Shashi Kanta
Ranch Hand

Joined: May 08, 2002
Posts: 89
i think u can do 1) and 4) in init() and destroy() methods respectively!!
bcoz when the servlet is deployed the first time, init() is called and when u r going to remove the application ie undeploy the servlet, destroy() will be called.
i haven't tried out though!
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
For 1) you could try javax.servlet.init() to initialize your webapp but preload the servlet first. You better add a first-time switch too in the ServletContext because that servlet instance may be replaced by the container (they can do that under certain conditions) and you don't want your entire webapp re-initialized whenever a new instance of that servlet enters service.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
or one could use "MUCH TALKED ABOUT" - Filters....
Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
Well, here is some info which could be useful.
OC4J supports a file, globals.jsa, as a mechanism for implementing the JSP specification in a servlet 2.0 environment.Within any single Java virtual machine, you can use a globals.jsa file for each application (or, equivalently, for each servlet context).The globals.jsa file also provides a vehicle for global Java declarations and JSP directives across all JSP pages of an application. The syntax for global.jsa file is as given below:-



Hope, this is helpful to others.I found this very useful as I have moved from ASP to JSP and Im used to global.asa
This is a part of document called JSP reference.It is available for download from oracle`s otn website under Oracle 9ias Containers for J2EE.Im using OC4J for my project, so it helps me out.
I agree. Here's the link:
subject: Session Start
jQuery in Action, 3rd edition