new HttpSession

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: new HttpSession

  1. #1
    horea Guest

    new HttpSession

    Can somebody tell me when and how ( based on what criteria ) the servlet container
    decides to create a new HttpSession ?

  2. #2
    Alex_dearmero Guest

    Re: new HttpSession

    "horea" <> wrote:
    >Can somebody tell me when and how ( based on what criteria ) the servlet

    >decides to create a new HttpSession ?

    In this example the jsp is invoking the user session bean and its labeling
    it as session. If it doesn't exists the servlet engine will create the httpsession
    with the values of the bean and automaticaly binds the session to the user

    <%@page import = "jspcourse.UserSession" %>

    <jsp:useBean id="userSession" class="jspcourse.UserSession" scope="session"/>

    <title> Login Session Test </title>

    User Id="<%=userSession.getUserId()%>" <br>

    how does it look in servlets?...
    if the parameter on getSession is true and the session does not exists yet
    on the server, the servelt engine creates a new one.

    HttpSession session = req.getSession(true);

    String user = (String) session.getValue(catalog.USER_DATA);

    if (user == null) {
    username = req.getParameter(catalog.USER_DATA);

    bind the username to a object named catalog.USER_KEY on the server or update
    the value.

    session.putValue(catalog.USER_KEY, username);

    to send the session to a next web component you should use URLencode method.

    Hope this helps


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center