Discussions

Web tier: servlets, JSP, Web frameworks: Session variables becoming null

  1. Session variables becoming null (11 messages)

    The application flow is:
    jsp -->servlet --->processor class -->session bean-->DAO -->database.
    The application server is oracle 9ias

    when two or more users access the application (same menu item) at the same time it gives nullpointer exception for all the users except one.Only one user is able to see the next screen.

    In the processor class we are setting the values in the session..but in the servlet when we try to print the session values in the servlet it is printing null for the users except for one ..

    Threaded Messages (11)

  2. Is it in a clustered environment?

    Senthil.
  3. Not clustered[ Go to top ]

    No.Its not in clustered environment.
  4. Not clustered[ Go to top ]

    I think you can use listeners like HttpSessionListener to find out when the session is destroyed. Check your code if you change the inactive anywhere.

    Senthil.
  5. Non clustered[ Go to top ]

    We implemented the above said Listener and we found that no session is invalidated in between and only sessionCreated() is invoked.
    Could u suggest something else?
    Or,is it the problem with the container itself?
    Please help us.............
  6. Hi Rashmi,

    Just to verify you are not declaring any variables at class level in your servlet apart from HttpSession object or Servlet Context object.Whatever processing or intialization you are doing must be in the servlet methods.

    for more clarity can you send me the code snippet of servlet and processor

    Cheers,
    Mohit
  7. Based on the request from JSP,the servlet parses the Mapping.xml(contains mapping b/n the request string ,processor class and the destination JSP) and invokes the process method in the respective Processor class(thro' reflection)
    In the Processor class,session beans are invoked for accessing the DAO to perform the db operations.
      This is the flow of the application.
    And to clarify ur doubt,we don't have any class level variables in the servlet.
    If this does'nt gives u the clear picture,let me know and i'll send the code snippet.
    Rashmi
  8. Can you try SingleThreadedModel interface?, anyway it is depricated in J2ee1.4

    Senthil.
  9. Actually i also faced the same problem in our project but it get resolved when i remove all the class level variables . i have to see ur servlet and processor code where u r storing session variables and retriving.
    As what Senthil suggest u can try a SingleThreadModel but u have to take a care lot about synchronization issues.
    -Mohit
  10. Hi Mohit,
      In all our processor classes,the HttpSesion object is at the class level.i.e,instance variable.Is that causing these problems?
    If so,please tell me what is the workaround for this .
    Reply needed urgently
  11. Just a sample of what i am doing:
    public class Gateway extends HttpServlet
    {
    HttpSession session;

    ServletContext scCtx;

        public Gateway() {
            scCtx = null;
        }

        //The init method takes care of all the initialization, and it made in such a way that, the inital class laoding time is high, but one the class is loaded the performance is max

        public void init(ServletConfig servletconfig)throws ServletException {
            //Calling the init of the super class
            super.init(servletconfig);
            //Getting the servelet context

            scCtx = servletconfig.getServletContext();

           System.out.println("Gateway Initialization");
        }


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
    session = request.getSession(true);
                    // call request processor class
            }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
    doGet(request, response);
    }
    }

    Just try this and let me know.
    -Mohit
  12. I think ,I got the solution.I found that the super class of the processor class genre had a set of static declarations for all the child processor classes and a static initializer which initialized these.
      I removed the static declarations for these and made them instance variables
    And fortunately,the application is able to handle 4 concurrent users and hope to take many such users,without a hitch.
    And ,I am thankful for all ur suggestions.