Lost session data on jsps

I run a jsp on Tomcat. But the Tomcat says that the session is lost and returns a null pointer. There is no session clear statement in my jsp except its pointing out a null session data.
It works well when I go to a jsp that comes from a servlet processing. But when I click on link that directly calls on a jsp page, the page doesn't finish loading/errs out.
What to do with this? This works fine in single-serevr instance. But when it's run on a cluster/shared environment, it doesn't.
Message was edited by:
rachehernandez

I'm new to tomcat itself and to this job :) I'm using tomcat 5.0.28.
I'm not sure how they do clustering in their setup though.
It's working fine by in a test standalone mode. I do think there's something wrong with the setup. But how would I know?
The jsp sometimes work , and most of the times not. It works when you try to refresh the page. It also works when it comes from a servlet call. But when its just an href link, it doesn't. JSP is using an object from the session. It throws an exception when it can't find this object in the session. But when I click on a link that calls a servlet to load a jsp that's using the same session object, how come it can load up.
What's happening with the session?
Thanks!

Similar Messages

  • How the hell does a person share session data between JSP page and a Servle

    1. How the hell does one share session data between a servlet and a JSP page without using a bean but rather using a normal string variable.
    2. When using session scope to access a bean the application complains about not finding the bean on the specified scope, however when I use an application scope the save the same bean, the application does find it.
    Please help!!!!!!!
    SERVLET:
    HttpSession session = request.getSession(true);
    ServletContext servletContext = session.getServletContext();
    customerID = result.getString("CustomerID");
    userName = result.getString("UserName");
    session.setAttribute("UserName",userName);
    session.setAttribute("CustomerID",customerID);
    System.out.println("Customer UserName = " + session.getAttribute("UserName"));
    response.sendRedirect("/economics/subscriptions/default.jsp");
    JSP PAGE:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root xmlns:jsp=http://java.sun.com/JSP/Page mlns:c="http://java.sun.com/jsp/jstl/core" xmlns:sql="http://java.sun.com/jsp/jstl/sql" version="2.0">
    <jsp:directive.page isThreadSafe="true" session="true" contentType="text/xml"/><jsp:output omit-xml-declaration="false"/><jsp:scriptlet>response.addHeader("x-xslt-nocache", "true");</jsp:scriptlet><pml>
    <page type="web" search="y">
         <pageName>Commercial Banking</pageName>
         <jsp:directive.include file="/economics/header.inc"/>
         <jsp:directive.include file="/login.inc"/>
         <jsp:directive.include file="/economics/leftMenu.inc"/>
         <!--<jsp:useBean id="UserName" type="java.lang.String" scope="session" />-->
         <content>
         <searchSum>Commercial - Main Content</searchSum>
         Value = <c:out value="${request.session.getAttribute("UserName")}"/>
         </content>
         <jsp:directive.include file="/economics/rightNav.inc"/>
         <jsp:directive.include file="/footer.inc"/>
    </page></pml></jsp:root>

    For a start, just "session" instead of "request.session" would work better. But why did you post this here and not in the JSP forum? Doesn't seem to have anything to do with Java programming.

  • Retrieving session data in JSP  which is forwarded from a servlet

    I'm trying to retrieve session data which is set in a servlet and pass to a jsp. But its returning NULL . The session IDs are equal.
    Scenario:
    JSP display the checkbox, user selects it and submits to a servlet. the servlet display the selected items and stores the data in session.
    when the user press back button in servlet all i want to do is display those checked box which were selected before as checked in the JSP so that user can edit.
    Following is a small test code
    JSP
    <html>
         <head>
              <title>Item List</title>
         </head>
         <body bgcolor="#fedeab"><br><br><br>
         <p align=center>
              <font size=4>
              Choose the item you want!!!
         </p>
         <form action="/demo/showitem" method="post">
              <%=session.getId()%>
              <div align=center>
              <fieldset style="width:250px">
              <legend style="text-align:center">List of item</legend> <br>
              <%     
                   if (session.getAttribute("book1")!=null) {
              %>
                   <input type="checkbox" name="book1" value="book1" checked > Book 1 <br>
              <% } else {%>
                   <input type="checkbox" name="book1" value="book1" > Book 1 <br>
              <% }%>
              <input type="submit" value="Enter">
              </fieldset>
              </div>
         </form>
         </body>
    </html>               
    Servlet
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ShowItem extends HttpServlet
         public void doPost (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              HttpSession session = req.getSession(true);
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.println(session.getId());
              out.println("<br>");
              out.println("<form>");
              String book1 = req.getParameter("book1");
              session.setAttribute("book1",book1);
              if (book1 != null)
                   out.println ("1." + book1 +"<br>");
                   out.println("<br><br><input type=\"submit\" name=\"buy\" value=\"Buy\">");
              else
                   out.println("No item to display<br>");
              out.println("&nbsp&nbsp<input type=\"submit\" name=\"back\" value=\"Back\">");
              out.println("</form>");
              RequestDispatcher page = getServletContext().getRequestDispatcher("/jsp/litemlist.jsp");
              if ((req.getParameter("buy"))!= null)
                        page.forward(req, res);
              if ((req.getParameter("back"))!= null)
                        page.forward(req, res);
         public void doGet (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              doPost(req,res);
    }

    req.getParameter("book1") is not NULL and returning the value of the checkbox "book1". The problem occurs when the back button is press and try to retrieve the session value in the JSP. At that time, session.getAttribute("book1") returns NULL.
    But if i convert the servlet to JSP then everything is working fine.
    So i wanted to know if there is anything wrong in the way i store the session value in the servlet and forwarding to the JSP.
    Thanks

  • Passing session data between jsp and servlet

    I have a servlet that I pass data to my jsp.
    I do a session.setAtrribute in the servlet. No problem.
    I get the data no problem in the jsp that I call.
    How do I pass this same data to the another servlet?
    I basically have an array of values that I already have in the existing jsp that has been set in session.
    When I call the secondary servlet, I don't have anything in this session variable related to my array.
    Prior to posting to my next servlet, do I need to do another setAttribute inside the jsp to get the data passed to the servlet?
    Thanks.

    Two different things. The encoding adds this to the URL (after the page, before the query string
    ;jsessionid=ABC123 but only if the user isn't using cookies.
    So in your example, you would do this (maybe):
    <%
      String url = response.encodeURL("Servlet");
    %>
      <form name="form1" method="post" action="<%= url %>?cmd=pay"> ... Or some modification.
    So the difference between encodeing and using a post is that
    1) encoding adds the jsessionid to the url string if necessary. It does nothing else
    2) POSTing will send a request to the provided URL via the POST method, including the inputs of the form as parameters to the URL.
    They really don't interact with each other. It is like asking what is the difference between the Color Orange and thr Size Big? They can both be applied to the same thing, or not... and have no real relation to each other.

  • Unable to create/cleanup persistent session data cache

    Hi all
    After the iPlanet Webserver 4.1 SP12 starts up the following entries appears in the error log file:
    [14/Oct/2003:09:24:48] info ( 5999): successful server startup
    [14/Oct/2003:09:24:48] info ( 5999): iPlanet-WebServer-Enterprise/4.1SP12 BB1-12/18/2002 14:18
    14/Oct/2003:09:24:49] catastrophe ( 5999): Unable to create/cleanup persistent session data cache
    What does the last entry mean?
    Thanks for any help :-}
    Best regards,
    Jean-Claude

    Check permissions, disk space of following dirs:
    server_root/https-instance/ClassCache/
    server_root/https-instance/SessionData/
    Try to:
    Clear Session Data
    Delete JSP Class Cache Files
    using the Session Data link under Admin Server GUI Java tab
    Hope it helps!

  • How to store jsp session data of different user in util.hashmap

    how to store jsp session data of different user in java.util.hashmap
    and access the data of all user on the server side
    The same example is given in professional jsp but its not working.
    I can use getIds() of httpsessioncontext but it's depricated

    Hi
    I'm trying to make an example.
    With the following codes you can get the date from the session.
    request.getSession().getAttribute("sessionname")
    To store it in a hashmap you could do it like this ->
    Hashmap hm = new Hashmap();
    hm.put(Object key, request.getSession().getAttribute("sessionname"));
    I hope you understand it if not just write it!
    Cyrill

  • Weblogic portal session data lost

    Hi,
    I have a peculiar scenario where the data set in the HttpSession gets lost intermittently. I could not really figure out a pattern where this occurs.It occurs any where in the application.
    I have a session listener tied to the Session which does not get triggered when the session data is lost in this manner. This makes me to believe that the session itself is not getting killed. but only the data gets lost.
    I am using Weblogic Portal Server 8.1 sp5 on UNIX server.
    Any help is greatly appreciated.
    Thanks
    Raj

    Well, we use the standard authentication:
    [url http://edocs.bea.com/wlp/docs81/javadoc/com/bea/p13n/security/Authentication.html#login(java.lang.String,%20java.lang.String,%20javax.servlet.http.HttpServletRequest)]
    Hope it will work in your case. Good luck.
    Edited by pecanov at 07/05/2007 1:41 PM

  • Session problem in JSP

    Good day to all!
    I have a JSP that generates an Excel document. I used the application/vnd.ms-excel in the contentType so that IE automatically opens Excel. I noticed that if I use IE 5.5 or 5, the data in the session, that I'm suppose to display in the excel worksheet, is lost. However, if I display the data having text/html as contentType, the browser is able to get the session data.
    Note that I don't encounter this problem if I use IE 6. If there's a problem about cookies or the like in IE 5.5, then why does it able to get the correct data in plain html?
    Any ideas?

    Anybody knows an answer to this problem?

  • How do I access session data through an EJB?

    Hi
    How do I access session data through an EJB?
    I am currantly developing a Web service (using ejb's, JBoss.net and Apache Axis). A client making a call to this Web service, is expecting a bussiness-object in return. My problem is that this bussiness-object i stored in a users session data. How do I retrieve this bussiness-object from the users session.
    I have read that this does not work with httpsessions, is this true? If this is true, is it possible to store the bussiness object in a JavaBean e.g:
    <jsp:useBean id="userContextWebImpl" scope="session" class="com.ac.march.client.UserContextWebImpl">
    <%
    String key = "test";
    String value = "This is the value";
    userContextWebImpl.setValue( key, value1 );
    %>
    </jsp:useBean>
    and then retrieve this information through the EJB? Or is it possible to do this by using Statfull JavaBeans? Or can this be done through a nother solution?
    Please help!

    I have created a JavaBean with scope="application" to store some data. The data is stored when a user prefomes a spesific task.
    A different person then makes a call to a Web-Service on the server. The Web-Service then asks an EJB to retrieve the data stored in the JavaBean (servlet cotext). In other words: How do I retrieve this data from the EJB?
    I have tried with this code, but with no luck.
    (ApplicationContextWebImpl is the JavaBean)
    public static String getBookingResult( String key )
         String myResult = null;
         String myKey = key;
         ApplicationContextWebImpl applicationContextWebImpl = null;
         try
              applicationContextWebImpl = new ApplicationContextWebImpl();
              myResult = (String)applicationContextWebImpl.getValue( key );
         catch ( java.rmi.RemoteException e )
         return myResult;
    }

  • Dates in JSP page

    I have some dates fields on JSP page I want to store data in mysql databse. Can someone tell me how I can format dates as I do for other data types in servlet before I send data to add in databse: such as
    For int type data:
    String paymentID = request.getParameter("PaymentID")
    I format it like this for class Payment.
    Payment newPayment(int.parseInt(paymentID)               
    how do i work with date fields this is what I Am trying to do:
    Code patches....
    import java.text.DateFormat;\import java.text.ParseException;
    public date date1;
    try                               
          date1= format.parse(paymentStartDate);
    catch(ParseException pe)
    System.out.println("Problem found");
    ....I do not get any error but it leaves date fields empty because date1 formatting never goes to try... Always say "Problem found on console"
    Any help?

    I just realized I should post the whole file... here is code of the servlet that recieved dates from JSP and process it.
    package admin;
    import java.lang.Object.*;
    import java.text.DateFormat;
    import java.util.Date;
    import java.io.IOException;
    import java.text.ParseException;
    import data.*;
    import business.*;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class AddPaymentServlet extends HttpServlet{
         public Date date1;
         public Date date2;
        public DateFormat format;
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
    // Stores user entered Payment information in variables to create new Payment vector
              String paymentID = request.getParameter("paymentID");
              String clientName = request.getParameter("clientName");
             String paymentType = request.getParameter("paymentType");
              String paymentAmount = request.getParameter("paymentAmount");
             String paymentStartDate = request.getParameter("paymentStartDate");
              String paymentExpiryDate = request.getParameter("paymentExpiryDate");
              String paymentDescription = request.getParameter("paymentDescription");
              String paymentState1 = request.getParameter("paymentState"); // use String type of PaymentType
    //-----------------------------------Format dates----------------------------------------------------------          
             DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT);
           //    System.out.println("Date1--->"+date1);
                  try
                       {    date1 = format.parse(paymentStartDate);
                        //    System.out.println("Date1--->"+date1);
                     catch(ParseException ps)
                            System.out.println("can't format dates");     
                      try
                       date2 = format.parse(paymentExpiryDate);
                  catch(ParseException pe)
                       System.out.println("can't format dates");
    // get old Payment object from session
    //--------------------------------Send new PAyment Information to Vector Payment in Payment.jave-----------------------------
              Payment newPayment = new Payment(clientName,paymentType,Double.parseDouble(paymentAmount),date1,date2,paymentDescription,paymentState1);
    //------------------------------ Call PaymentDB function Add() to store new payment infomration in the databse
             PaymentDB.addRecord(newPayment);
    // over-write Payment object in session
              request.getSession().setAttribute("payment",newPayment);
              request.getSession().setAttribute("payments",PaymentDB.readRecords());
    //---------------------------------- Send results back to payment.jsp for updated information----------------------
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Admin/payments.jsp");
              dispatcher.forward(request, response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
              doGet(request, response);
    }

  • Window open lost session

    I have a jsp app and it lost session when I try to popup new window
    Googled around, millions of results but no helps
    It seems problem is in my IE 8
    If anyone has expeience with the issue, please give me a help. Thank you
    Edited by: mycoffee on Jul 28, 2010 1:45 PM

    Solved
    Solution: Reboost the machine
    Sorry guys

  • Tomcat 5.0.25 persisting session data by default ?!?

    This is, I imagine, a dumb question, but I can't quite figure out what is happening by looking at past postings.
    When I start Tomcat I get an error : "IOException while loading persisted sessions" because some classes we use are not serializable. That makes sense - we didn't design them to be serialized.
    I understand that Tomcat CAN try to persist session data across restarts. However, I do not want it to do this. I thought this was something we had to configure, but it looks like it happens by default (?)
    Anyway ... any advice about how to prevent this behavior, at least for our app, would be appreciated ... really puzzled ... !
    Thanks in advance for any help you can give !!
    ethan

    Well, thanks ... I have been there actually, but it only tells me how to set up the 'Experimental" Persistent Manager and not how to turn this off. Here is an interesting blurb from that site :
    <<<<<
    Whenver Catalina is shut down normally and restarted, or when an application reload is triggered, the standard Manager implementation will attempt to serialize all currently active sessions to a disk file located via the pathname attribute. All such saved sessions will then be deserialized and activated (assuming they have not expired in the mean time) when the application reload is completed.
    In order to successfully restore the state of session attributes, all such attributes MUST implement the java.io.Serializable interface. You MAY cause the Manager to enforce this restriction by including the <distributable> element in your web application deployment descriptor (/WEB-INF/web.xml).
    >>>>>>>
    I THINK this means that persitence is on by default. I'm not certain because - if that is true - then what is the Persisistent Manager for ? I have found thi ssnippet of config in conf/server.xml :
    <<<<<<
    <Context path="/myApp" reloadable="true" docBase="myApp" workDir="C:\myApp\\work\org\apache\jsp" >
    <Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="false"/>
    </Context>
    >>>>>>
    which tells Tomcat to use the Persistent Manager for my app and then ... tells it not to store session data. And this seems to work ... at least the error messages go away. Now, though, I get a new and different error message :
    <<<<<<
    SEVERE: no store configured, persistence disabled
    >>>>>>
    So I am still doing something wrong ... I think ... and still looking for help ... B-)
    Thanks again, black_lotus ... maybe we'll learn about this together ;-)

  • Save the session data in the database !

    Hello everybody,
    I read an article on JavaWorld website about saving the session data of an application in the database instead of mantaing them in memory.
    In this way, the web application is more scalable and in case the application server crashed the session data can be taken by another application server.
    I was sure that this was a good motivation of writing a class to save the session data of my application in the database, but i read another article where a good methodology to
    create a scalable web application was to save the session data in more application server so if one application server crashed another application server can take the control of the entire application.
    I think that at the moment i have just a bit of confusion in my mind.
    Any suggestion ?
    Cheers.
    Stefano

    What you've read was a method of "load balancing" where "state" is maintained by a backend server instead of the web servers themselves. Yes, if done properly, this would achive true web server independance, and if one crashed, another would pick up where it left off. Of course, you'll still need an HTTP load balancer in front of the web server farm, so it can dynamically shift the load.
    From an architecture standpoint, it's a good way to go, but only IF you really need 7x24 with zero downtime. Reason being twofold. 1) It's a huge performance hit, becase each GET/POST requires a trip to the DB, because it's holding state. 2) It's a lot of work, because you're now taking on the role of "managing" sessions (e.g. when to expire, reading the cookie/URL for session IDs.
    I was once responsible for a 7x24 Intranet that ran core business applications. My service level agreement with my customers was 7x24 alright, but with the risk of a possible "blip" (meaning, if one server crashed, simply reconnect and continue your work). Worst case, one lost just that one page worth of work.
    I hope that helps explain!
    bRi

  • Calling Session Beans in JSP ?

    Hi Folks,
    I am new to EJB3, I am doing simple applicatuions.
    Can any one please tell me how to call session beans in jsp page.
    for example my case is.. iam entering two diffrent data, lets say user name and password in jsp page and this should go in data base thru JPA (entity beans)
    Iam able to enter data from JPA in data base but if the same i have to fetch from JSP page.. iam not getting..!
    I would really appretiate for your help i need it urgent...!
    thanks in advance.

    abishek1983 wrote:
    Hi Folks,
    I am new to EJB3, I am doing simple applicatuions.
    Can any one please tell me how to call session beans in jsp page.
    Not. You can, technically, but you shouldn't. JSP should be for display purposes only, containing no Java code whatsoever.
    for example my case is.. iam entering two diffrent data,Wrong. You cannot possibly have "2 data", the very concept is impossible.
    You can have "2 data items" which is probably what you intended to say?
    lets say user name and password in jsp page and this should go in data base thru JPA (entity beans)
    Iam able to enter data from JPA in data base but if the same i have to fetch from JSP page.. iam not getting..!
    Same way you insert them. Of course JPA entities are distinctly different from entity beans. The very concept of entity beans no longer exists in the context of JPA, it's solely used to mean EJB 2.1 or earlier entity beans.
    I would really appretiate for your help i need it urgent...!
    It's not urgent.

  • First Hit Session Data Replication

    We are using WLS 5.1 with sp3 in a cluster of three
              servers using in-memory-rep, JSP, and Apache as our proxy.
              Session data replication between a primary and secondary server
              seems to work fine except in the following case:
              1) Make first hit to the cluster. During the JSP processing of
              that hit set some HTTP session data via setAttribute().
              2) Kill-off the primary server (the one that handled the first hit).
              3)Make a second hit to the cluster, it is handled by another
              server (the secondary), the session is recognized as an ongoing
              session however the session data that was set during the first hit is not
              present in the second hit.
              If we make two hits to the first server and set data, then kill-off
              the primary server, the secondary has the data at the third hit. The
              only issue seems to be when the primary is killed after the first hit.
              Anyone have any ideas?
              Thanks,
              -darren
              

    You can configure ClusterServlet in your web server farm (WLAS as web
              servers) to proxy JSP and servlet requests to the WLAS farm (WLAS processing
              your JSP and servlet).
              Set up in-memory replication in your WLAS farm. Session in JSP will be
              replicated.
              Cheers - Wei
              Yen Liu <[email protected]> wrote in message
              news:[email protected]...
              > Hello,
              >
              > I read breifly the section on BEA's online documentation talking about
              in-memory
              > replication and clustering.
              >
              > In it, it mentioned the ClusterServlet and configuring the
              weblogic.properties
              > file to assign servlets to the ClusterServlet so that sessions will be
              handled
              > correctly and all.
              >
              > My question is, "what about JSP" I am using a lot of JSP pages which sets
              > session parameters for the specific user into session objects.
              >
              > Any tips, recommendations will be most helpful.
              >
              > Thanks,
              >
              > Yen Liu
              > 510/870-1169
              >
              > Prasad Peddada wrote:
              >
              > > Darren,
              > >
              > > It shouldn't be the case. After your first hit, when you kill the
              primary
              > > server, when you make your next request you should find all the info in
              the
              > > session. I will post again, if we find the same problem on monday in our
              test
              > > environment.
              > >
              > > Thanks
              > >
              > > Prasad
              > >
              > > Darren Kessler wrote:
              > >
              > > > We are using WLS 5.1 with sp3 in a cluster of three
              > > > servers using in-memory-rep, JSP, and Apache as our proxy.
              > > > Session data replication between a primary and secondary server
              > > > seems to work fine except in the following case:
              > > >
              > > > 1) Make first hit to the cluster. During the JSP processing of
              > > > that hit set some HTTP session data via setAttribute().
              > > > 2) Kill-off the primary server (the one that handled the first hit).
              > > > 3)Make a second hit to the cluster, it is handled by another
              > > > server (the secondary), the session is recognized as an ongoing
              > > > session however the session data that was set during the first hit is
              not
              > > > present in the second hit.
              > > >
              > > > If we make two hits to the first server and set data, then kill-off
              > > > the primary server, the secondary has the data at the third hit. The
              > > > only issue seems to be when the primary is killed after the first hit.
              > > >
              > > > Anyone have any ideas?
              > > >
              > > > Thanks,
              > > >
              > > > -darren
              >
              

Maybe you are looking for

  • Insert data from a table

    <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Hi,</font></p> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">I would like to insert data in a table. The

  • ITunes library not available for two computers on shared external hd

    On our home network, using Airport Extreme, we have and external hd, and two mac laptops connected. We have all music in an iTunes music folder on the external hd plus the iTunes Library on the external hd. iTunes will only allow one laptop to connec

  • NI6554 Dinamic generation with external sample clock

    I am using the PXI-NI6554 to generate a digital signal, as clock I want to use an external source that I drive in the board via de CLK IN SMB connector. Always I got the same error (cod: 1074115898) from the "Write" VI block, the reason is that there

  • Adobe Air won't install on android device.

    Just got a android phone to develop air apps on and guess what, the Adobe Air won't load. The phone (Virgin Mobile Optimus V = Mid-Tex Cellular LGE VM670) was just released. Does Adobe Air have minimum specs that have to be followed? Does the Adobe A

  • Help on analytical and hiererarchial queries

    Hi, could any one please throw some light on the usage of analytical and hiererchial queries please.