7 Replies Latest reply on Feb 15, 2003 11:36 PM by Roozbeh

    Session management in JBOSS 3.0.2 with Jetty

    Rakesh Newbie

      Hi All,

      I had posted this problem in Beginer forum but later realized that this will be a better place.

      I am facing a typical problem(as seen in previous postings) of session management in JBoss3.0.2 with Jetty

      It create a new session for every servlet in my context and the information stored by the previous servlet is totally lost. Any suggestion or pointers would be highly appreciated.

      I did look at some postings in this forum but they are not very clear. I feel this must be a default implementation hence not covered in detail in the Quick Start pdf guide.

      I am not trying to use distributed sessions.

      thanks in advance.

        • 1. Re: Session management in JBOSS 3.0.2 with Jetty
          Julian Gosnell Expert

          Do you mean that you wish to preserve session contents across restarts of JBoss ? or something different ?

          Jules

          • 2. Re: Session management in JBOSS 3.0.2 with Jetty
            Rakesh Newbie

            Hi Jules,
            Thanx for ur concern.. Actually I want the session to
            be active accross all the servlets in my webapp...
            I just want the session info to be available to me when I move from one servlet to another...

            I am not trying to preserve session contents across restarts of JBoss ...

            thanks again.

            • 3. Re: Session management in JBOSS 3.0.2 with Jetty
              Julian Gosnell Expert

              I don't whether me reply made it - so :

              Sessions are scoped within a context/webapp.

              To declare that all your servlets shuold be able to see the same session package the, all in the same war/webapp.

              Jules

              • 4. Re: Session management in JBOSS 3.0.2 with Jetty
                Rakesh Newbie

                Hi Jules,
                Yeah, all the servlets are in the same .war file.
                See I just want my session to remain when I move from
                one servlet to another within same webapp.

                These things are pretty simple in WebLogic, Tomcat etc. I don't know what's the problem here... Is there any setting to be done in jetty or some file in jboss to enable the session....??

                Thanx again,
                DTL

                • 5. Re: Session management in JBOSS 3.0.2 with Jetty
                  Julian Gosnell Expert

                  It should work.

                  Are you sure it doesn't.

                  Have you got something that works in Tomcat and doesn't in Jetty ?

                  Please describe the exact steps to replicate your problem.

                  Jules

                  • 6. Re: Session management in JBOSS 3.0.2 with Jetty
                    Rakesh Newbie

                    Hi Jules,

                    The following is the explanation of my code.

                    1) Browser displays the login.jsp which has accepts User Id & Password.
                    2) On click of Submit, the control goes to the LoginControllerServlet?action=validate which validates the user id & password entered by the user. Currently, in this code, the User is hardcoded as "ABC".
                    3) The LoginControllerServlet forward the controls to the ManageForumServlet?action=listAllForums which in turn displays the DisplayForums.jsp which shows some hyperlinked names. i.e.
                    JBoss 3.0.2
                    4) On click of hyperlink, the control again goes to the ManageForumServlet?action=listAllTopics which displays the DisplayTopics.jsp

                    The session works fine till point 3. But when we click on hyperlink (i.e executing step 4), the session object appears as null.

                    The same code works fine under Tomcat 3.2.4.

                    Please help. Thanks for your co-operation.

                    The following is my code.

                    1) LoginControllerServlet.java
                    --------------------------------

                    package de.mms_dresden.impetus.login;

                    import javax.servlet.ServletConfig;
                    import java.io.IOException;
                    import java.io.PrintWriter;
                    import java.util.Hashtable;
                    import java.util.ArrayList;
                    import javax.servlet.ServletException;
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    import javax.servlet.http.HttpSession;
                    import javax.naming.Context;

                    public class LoginControllerServlet extends HttpServlet
                    {
                    public void init(ServletConfig config ) throws ServletException
                    { super.init(config); }
                    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
                    doPost(request, response); }

                    public void doPost(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {
                    HttpSession session = null;
                    String lstrAction = request.getParameter("action");
                    String lstrRedirectPageTo = null;
                    if (lstrAction != null && lstrAction.equals("login")) {
                    lstrRedirectPageTo="/jsp/login/login.jsp"; gotoPage( lstrRedirectPageTo, request, response);
                    }
                    else if (lstrAction != null && lstrAction.equals("validate")) {
                    String lstrUserId = request.getParameter("txtUserId");
                    String lstrPassword = request.getParameter("txtPassword");
                    String strValidateUser = null;
                    if(lstrUserId != null && lstrPassword != null) {
                    strValidateUser = "ABC";
                    System.out.println("strValidateUser " + strValidateUser);
                    if (!strValidateUser.equals("")) {
                    session = request.getSession(true);
                    ArrayList larrAllForums = new ArrayList();
                    System.out.println("larrAllForums = " + larrAllForums);
                    System.out.println("Calling ManageForumServlet");
                    lstrRedirectPageTo = "/servlet/ManageForumServlet?action=listAllForums";
                    gotoPage( lstrRedirectPageTo, request, response);
                    }
                    else {
                    String lstrError = "Error : Invalid UserId/Password";
                    session.setAttribute("LoginError",lstrError);
                    lstrRedirectPageTo = "/jsp/login/login.jsp";
                    gotoPage( lstrRedirectPageTo, request, response);
                    }
                    }
                    else {
                    session.setAttribute("LoginError","Error : Invalid UserId/Password");
                    lstrRedirectPageTo = "/jsp/login/login.jsp";
                    gotoPage( lstrRedirectPageTo, request, response);
                    }
                    }
                    else if (lstrAction != null && lstrAction.equals("logout")) {
                    lstrRedirectPageTo = "/jsp/login/login.jsp";
                    gotoPage( lstrRedirectPageTo, request, response);
                    }
                    else {
                    lstrRedirectPageTo = "/jsp/login/login.jsp";
                    gotoPage( lstrRedirectPageTo, request, response);
                    }
                    }

                    public void gotoPage( String astraddress, HttpServletRequest req, HttpServletResponse res )
                    throws ServletException,IOException {
                    req.getRequestDispatcher( astraddress ).forward( req, res );
                    return;
                    }

                    }

                    2) ManageForumServlet.java

                    package de.mms_dresden.impetus.forum.forum;

                    import javax.servlet.http.HttpServletResponse;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpSession;
                    import javax.servlet.ServletException;
                    import javax.servlet.ServletConfig;
                    import java.util.Hashtable;
                    import java.io.IOException;
                    import java.net.URLEncoder;

                    public class ManageForumServlet extends HttpServlet {

                    public void init( ServletConfig config )
                    throws ServletException {
                    super.init(config);
                    } /* init() */

                    public void doPost( HttpServletRequest req, HttpServletResponse res )
                    throws ServletException, IOException {
                    System.out.println("Request Object = " + req);
                    HttpSession session = req.getSession(false);
                    System.out.println("session object = " + session);
                    System.out.println("In ManageForumServlet.doHttp()");
                    String lstrOption = req.getParameter("action");
                    if (lstrOption.equals("listAllForums")) {
                    String lstraddress = "/jsp/forum/DisplayForums.jsp";
                    req.setAttribute("CenterJSP",lstraddress);
                    String lstrRedirectPageTo = "/jsp/generic/main.jsp";
                    gotoPage( lstrRedirectPageTo, req, res);
                    }
                    else if(lstrOption.equals("listAllTopics")) {
                    String lstraddress = "/jsp/topic/DisplayTopics.jsp";
                    req.setAttribute("CenterJSP",lstraddress);
                    String lstrRedirectPageTo = "/jsp/generic/main.jsp";
                    //gotoPage( lstrRedirectPageTo, request, response);
                    gotoPage(lstrRedirectPageTo, req, res);
                    }
                    else if(lstrOption.equals("")) {
                    }
                    } /* handleRequest() */

                    public void doGet( HttpServletRequest req, HttpServletResponse res )
                    throws ServletException, IOException {
                    doPost(req,res);
                    }

                    public void gotoPage( String astraddress, HttpServletRequest req, HttpServletResponse res )
                    throws ServletException,IOException {
                    req.getRequestDispatcher( astraddress ).forward( req, res );
                    return;
                    }


                    }

                    • 7. Re: Session management in JBOSS 3.0.2 with Jetty
                      Roozbeh Newbie

                      Hi,

                      Did you come up with a solution? I have the same problem. This is ridiculous. This is one of most basic features a servlet container should have.

                      Roozbeh/