java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips
 
 
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: 4084
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:
 
 
 
How to set session time of a servlet in web.xml E-mail
User Rating: / 47
PoorBest 

This J2EE tip describes a method of setting session time in web.xml. Session time of a servlet may be set based on the requirement of the application. This may limit the session to a particular time interval and restrict the client that is accessing the session to use it indefinately.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class SessionTime extends HttpServlet {
  int  i = 0;
  public void doGet(HttpServletRequest request , HttpServletResponse response)
       throws ServletException , IOException {
    i++ ;
    Integer a = new Integer(i);
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    HttpSession sess = request.getSession(true);
    
    // If the session doesnt exist a new session will be created
    sess.setAttribute("MySession",a);
    Object b = sess.getAttribute("MySession");
    
    // Exatract the session set previosuly
    out.println("You Have Visited This Page"+b);
  }
}

Here is the web.xml for the servlet. Session time out should be specified in minutes.

<web-app>
<servlet/> // Write Appropiate code
<servlet-mapping/>// // Write Appropiate code
<session-config>
<session-timeout> 1 </session-timeout >
</session-config> 


 Related Tips

 
< 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.