java left logo
java middle logo
java right logo
 

Home arrow Java Tutorials arrow Introduction to Servlet Listener using Eclipse
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Introduction to Servlet Listener using Eclipse E-mail
User Rating: / 258
PoorBest 

Implementation of ServletContextListener

As you may have known, ServletContextListener is useful if you would like to initialize your web application with some values in the beginning of your web application. Okay, without wasting any more time, let’s start our first Listener which is ServletContextListener.

Right click on the src folder (this is your source folder) and choose New and Class. Although Listener is part of Servlet, we can simply create it as a simple Java class. Subsequently, we need to customize it to be a Listener. Do not worry; it would not be too hard. Please follow the tutorial and you should see how we convert this simple Java class to Listener.


Image

In this wizard, you may define the package for your Java class. Normally, we use Package to group a few Java files that has the same functionalities. For example, if I have StringUtil.java for String manipulation and EncodingAlgorithmUtil.java for encoding, I will locate them under the same package called “com.mycompanyname.util” as they both are actually utility classes. So as this is our first Listener, let’s create one package called “com.mycompany.listener”. The class name is basically your Listener name. To make it self-explanatory, I name it ServletListener. You can leave other configuration as they are.


Image

Once it is completed, it should look like below.


Image

Now, the most important thing is that we need to make the class “implements” the ServletContextListener. So here is my latest ServletListener.java.


Image


 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.