Session (attribute) lost between JSPs

Hi All
I've seen many post about losing the session but all of them (the ones I've seen) are different.
Anyway, I have 3 jsp's, the first only submits a form like
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>The second one stores the username in the session like
<%
   String name = request.getParameter( "username" );
   session.setAttribute( "theName", name );
%>
<HTML>
<BODY>
Your name is <%= session.getAttribute( "theName" ) %><br/>
<A HREF="NextPage.jsp">Continue</A>
....So far everything works fine!
Then, when I click on continue the third jsp is reached:
<HTML>
<BODY>
Hello, <%= session.getAttribute( "theName" ) %>
</BODY>
</HTML>This is only basics, but the last jsp shows 'null' instead of the name.
I'm runnint tomcat6 behind apache. The only thing added to the apache configuration was
ProxyPass /tomcat/ ajp://localhost:8010/Maybe I need to do more configuration ? Any suggestions ?
Thnx
LuCa

Hi,
This should never really happen when you bring up a Web Server or to what so called a loadbalancer in place as ultimately the container which creates the session Object.
I strongly feel that the Webserver(Apache,Sun App Server or IIS) is not passing on the jessionid cookie value which is actually responsible for this action when we are not using url writing for maintaining. .
How do test that ??
try the below code snippet and the rest all is understood on what values you get.
<%
   //Get the values of respective Properties
   boolean sessionIdFromCookie = request.isRequestedSessionIdFromCookie();
   boolean sessionIdFromUrl = request.isRequestedSessionIdFromURL();
%>
From Cookie : <%=sessionIdFromCookie%>
From URL : <%=sessionIdFromUrl%>Well to sort out problems as these you got to enable passing of jsessionid cookie to the Application Context via Webserver which might call for additional set of configurations from webserver end and AJP part.
Just as an example let us consider in the case employing IBM http server
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/xjta_ihs_int.htmlor a neutral way to fix this issue is to adopt usage of a technique called URLREWRITING.
How do you do that ??
A quick google search provided me the below results
http://publib.boulder.ibm.com/infocenter/wchelp/v5r6/index.jsp?topic=/com.ibm.commerce.admin.doc/tasks/tseurlrewrite.htm
http://www.adventnet.com/products/qengine/help/load_testing/loadscript_creation/recording_bc/url_rewriting.html
http://java.boot.by/wcd-guide/ch04s04.htmlHope this might help :)
REGARDS,
RaHuL

Similar Messages

  • Session Data Lost Between JSP's

    Hello,
    I am using Oracle 10g Application Server (9.0.4) on SunOS 5.8. I am trying to upgrade an application previously written for Oracle 9iAS 9.0.2.
    A single JSP (myFile.jsp) is called via a POST operation, and it is initally used to create a frameset that contains two frames. Each frame has a URL link to the same JSP file, with some additional parameters:
    <frameset border="0" rows="*,70">
    <frame NAME="topFrame" SRC="myFile.jsp?PARAMETER1=hello&amp;PARAMETER2=goodbye"/>
    <frame NAME="bottomFrame" SRC="myFile.jsp?PARAMETER1=hello&amp;PARAMETER2=goodbye"/>
    </frameset>
    The problem is that when myFile.jsp is called to generate the actual page for the frames, all the HttpServletRequest data has gone, and only the parameters passed in the Query String remain. I don't want to lose the original POST data - in fact, when I used this on Oracle 9iAS 9.0.2 it preserved the POST data and added the additional queries from the query string so all the parameters were available.
    Has the behaviour of the session manager changed that much between Oracle 9iAS and Oracle 10g 9.0.4? How can I achieve my goal on 9.0.4?
    I tried adding the original POST request to the HttpSession variable as follows:
    session.setAttribute("PARENT_REQUEST",request);
    and then extracting the request data when the JSP is called on subsequent occasions as follows:
    HttpServletRequest newRequest = (HttpServletRequest) session.getAttribute("PARENT_REQUEST");
    But 'newRequest' is actually empty, and it doesn't create an exception. If I debug the session object I notice 2 things:
    1. The session ID remains the same througout all calls of myFile.jsp.
    2. The memory location pointed to by the parameter "PARENT_REQUEST" also remains the same, in the format:
    com.evermind.server.http.AJPHttpServletRequest@1bd5093
    If the session object being passed around by cookies remains consistent, why can I not extract the PARENT_REQUEST attribute from it on subsequent calls to myFile.jsp? Have I misunderstood how HttpSession works? How can I modify my JSP's so that data stored during a session is made available to subsequent calls to myFile.jsp?
    I appreciate any insight you can offer!

    Has the behaviour of the session manager changed that much between Oracle 9iAS and
    Oracle 10g 9.0.4? How can I achieve my goal on 9.0.4?If your experience did suggest something has changed from 9.0.2 to 9.0.4, I would believe that it is more about request management.
    If the session object being passed around by cookies remains consistent, why can I not
    extract the PARENT_REQUEST attribute from it on subsequent calls to myFile.jsp? Have
    I misunderstood how HttpSession works? How can I modify my JSP's so that data stored
    during a session is made available to subsequent calls to myFile.jsp?The "request" in the following code
    session.setAttribute("PARENT_REQUEST", request);
    is just a pointer to the actual request object. Other code, especially the server internal code that manage the http requests and responses can see and manipulate that actual request object. For example, although I am not sure if it is the case, the request objects can be pooled and reused. So it is possible that although "The memory location pointed to by the parameter "PARENT_REQUEST" also remains the same, in the format: com.evermind.server.http.AJPHttpServletRequest@1bd5093", the actual request object at that memory location may have changed. The right way to preserve the original request object is to make a private deep copy of it; however there is no easy way to do that.
    Well, an easy way out is to store directly what you need from the original request. If you would like to store the parameters, try
    session.setAttribute("origParams", request.getParameterMap().clone());
    Although this clone() does a shallow copy, it is probably good enough. To be absolutely sure, you can make a deep copy of everything you need and store them.
    Good luck!

  • Session getting lost between JSPs

    Hi,
    I am working on a application in which a user can upload files using FTP. The files may be of large size, say 50-100 MB and it takes approx 30-60 mins for such uploads. The session timeout for the website is set to 20 mins. The way it works is, from the main browser window there is a link to upload files. This link opens a popup window and through this window the user can upload a file. In this popup window, i have included an iframe which sends a post request to the server every 10 mins to keep the session alive. This is working fine in most of the cases, but sometimes it happens that when the when a call is made to send a post request to the server from the iframe, the session is becoming null & invalid or this happens also after the upload has finished and the "upload successful" page gets loaded. This is a very random behaviour, sometimes it works perfectly fine and sometimes it doesn't. It is not dependent on the time, or the size of the file or the number of times the iframe has submitted the request to the server.
    Any one has any idea why the session is becoming null randomly?

    Hi,
    This should never really happen when you bring up a Web Server or to what so called a loadbalancer in place as ultimately the container which creates the session Object.
    I strongly feel that the Webserver(Apache,Sun App Server or IIS) is not passing on the jessionid cookie value which is actually responsible for this action when we are not using url writing for maintaining. .
    How do test that ??
    try the below code snippet and the rest all is understood on what values you get.
    <%
       //Get the values of respective Properties
       boolean sessionIdFromCookie = request.isRequestedSessionIdFromCookie();
       boolean sessionIdFromUrl = request.isRequestedSessionIdFromURL();
    %>
    From Cookie : <%=sessionIdFromCookie%>
    From URL : <%=sessionIdFromUrl%>Well to sort out problems as these you got to enable passing of jsessionid cookie to the Application Context via Webserver which might call for additional set of configurations from webserver end and AJP part.
    Just as an example let us consider in the case employing IBM http server
    http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/xjta_ihs_int.htmlor a neutral way to fix this issue is to adopt usage of a technique called URLREWRITING.
    How do you do that ??
    A quick google search provided me the below results
    http://publib.boulder.ibm.com/infocenter/wchelp/v5r6/index.jsp?topic=/com.ibm.commerce.admin.doc/tasks/tseurlrewrite.htm
    http://www.adventnet.com/products/qengine/help/load_testing/loadscript_creation/recording_bc/url_rewriting.html
    http://java.boot.by/wcd-guide/ch04s04.htmlHope this might help :)
    REGARDS,
    RaHuL

  • Some session attributes lost

    hi
    traversing between different jsp pages,
    I find that three of the session attributes are lost.
    While it is set, I can print it and verify that it exists in the session.
    Is there any limit on the #, or is it something else.
    thanks in advance
    babu

    hi
    traversing between different jsp pages,
    I find that three of the session attributes are lost.
    When it is set, I can print it and verify that it exists in the session. But, when another page is called and then if I check, it is not present.
    Is there any limit on the #, or is it something else.
    thanks in advance
    babu

  • Accessing session attribute in output jsp page

    Hi i am not getting any output in jsp page...
    i am getting just heading
    i think some problem with Session attribute..
    if so how to access session been in jsp page
    my code is here
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Tauvex Search Output</title>
    </head>
    <body>
    Tauvex Search Output
    <table>
    <c:forEach items="${myDataList}" var="myData">
    <tr>
    <td>${myData.Fitsfilename}</td>
    <td>${myData.RA_START}</td>
    <td>${myData.RA_END}</td>
    <td>${myData.DEC_START}</td>
    <td>${myData.DEC_END}</td>
    <td>${myData.telescope}</td>
    <td>${myData.STARTOBS}</td>
    <td>${myData.ENDOBS}</td>
    <td>${myData.FILTER}</td>
    </tr>
    </c:forEach>
    </table>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    plz reply soon
    thanks a lot

    this is what i set in servlet
    request.setAttribute("myDataList", myDataList);
    request.getRequestDispatcher("someJspFile.jsp").forward(request, response);
    how can i access that session attribute in jsp

  • Session getting lost between two applications deployed on two WLS versions.

    Hi,
    Jdev version 11.1.1.5.
    I am facing an issue of session being getting lost. Let me explain the scenario.
    Our client has a legacy application(xyz) running on Web logic server(10.3.3). We have developed an application which was deployed on Web logic Server(10.3.5).
    The Legacy application will call the developed application using URL invocation. In the legacy application, the logged in user information is stored in session and the same parameter is appended to URL to call the developed application.
    In the developed application, we have a servlet which reads the URL and based on the parameter appended to it, we set the context of the application. Everything is working fine till here.
    But, in the developed application, we have a link to navigate to the legacy application. Once navigated, in legacy application if the user again calls the developed application, the session which was set earlier is lost.
    Because of this, the context is not getting set in the developed application.
    Is there a way, I can resolve this issue? OR can I raise SR with Oracle to look into it. Please suggest.
    Thanks,
    Umesh

    Thanks Frank for the reply.
    Session sharing was not configured in WLS.
    I was searching for Session sharing and I found this article written by Lucas Jellema. http://technology.amis.nl/2012/01/18/sharing-session-state-between-jee-web-application-through-weblogic-session-descriptor-of-sharing-enabled/
    Here it is mentioned that for session sharing, we need to check the Enable session sharing in weblogic-application.xml.
    My question is do we need to make this change in both the application? i.e Legacy application and developed application.
    And it was mentioned in the article that both the web app were deployed to a single Web Logic Server. But in my case the Legacy application is deployed to 10.3.3 and developed application is deployed to 10.3.5.
    In this case will the session sharing works?
    Any how I will let our client know about this change and will give a try.
    Thanks,
    Umesh

  • Session attribute between JVMs

    Hi,
    I have a JSP try to send two session attribute from one JSP to another. The target JSP is in different WEB server (JVM). How can I do so that target JSP can use "session.getAttribute" to get the attribute?
    1. Cann't use any JAVA Script in JSP.
    2. Conn't show or send hidden because I don't want let user see the value of the variable.
    Thanks
    Kenny

    SEND IT VIA HIDDEN BUT INSTEAD OF USING GET METHOD USE POST TO ADDRESS YR SECURITY CONCERNS

  • Strange problem - session attribute

    Hi,
    This one is really strange. I have a search field on my form. When I enter a value in the field(say 'test data') and then click 'Submit', the search is performed. To retain the above search value on the screen, I put it into a session attribute and then pick it up again from there.
    The problem is, when the screen reloads after the search, only the first part of the string i.e 'test' is displayed and data disappears. Is it that when get values of session attributes in a JSP, only the value till an empty space is considered?
    I would be grateful if someone could let me know if they have ever experienced the same of if there is any documentation stating this. I am totally lost!
    Thanks in advance.

    Greetings,
    Could you please include some of your code. It seems like somewhere along the process you are either losing or not storing all the data properly.
    Thanks,
    -J

  • How to set session attributes in a bean?

    How do I set a session attribute in a server-side bean?
    I'm not sure if I asked the question the right way. What I meant is, while it's easy to set session attributes in a JSP page (session.setAttribute("sessionname", "sessionvalue")), I'd want to set such an attribute within a server-side bean defined in this web application. But what is the syntax for doing it?

    Here a simple bean that stores something in the session and retrieves something from it.
    import javax.servlet.http.HttpSession;
    public class TestBean {
      private String value;
      public void doSomething(HttpSession session, int a, int b) {
        if (a+b > 0) {
          session.setAttribute("ab",Boolean.TRUE);
        } else {
          session.setAttribute("ab",Boolean.FALSE);
      public void init(HttpSession session) {
        if (session != null) {
          Boolean b = (Boolean)session.getAttribute("ab");
          if (b == Boolean.TRUE) {
            value = "a + b is greater than zero";
          } else {
            value = "a + b is not greater than zero";
        } else {
          value = "no session";
      public String getValue() {
        return value;
    }In your JSP, use something along the lines of :
    <%
      TestBean bean = new TestBean();
      bean.init(session);
      bean.doSomething(session,1,2);
    %>If your bean only lives during one request, you can pass the session to the constructor, which stores it in a private variable. This saves passing the session each time.
    Hope this helps,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Jsf issue using session attributes

    I have a JSF issue where I can't seem to get session attributes to be stored as initial values on my inputText field below. I've tried 2 things: (1) reading session attributes in my locrateForm bean, and then use getter method to get them to the jsp form ( I read the session attributes in the getter - I know it's a no-no, but I'm desparate)...
    (2) reading session attributes in my jsp and storing them to the inputText fields.
    Both times, I can successfully read the session attributes, but I can't get it stored in the inputText below....Pls provide this new jsf user some direction...thanks in advance...
    Also....I thought the below EL would auto-invoke the getter method in the "locrateForm" Bean to get the initial value, but it's not...my books don't explain this well...
    <h:inputText id="locrateDest" value="#{locrateForm.locrate.locrateDest}" >
    </h:inputText>

    Can you show us the snippit of your faces-config.xml for locrateForm and the snippit of the Java implementation that involves locrate and locrateDest?

  • How to transmit session attributes

    I am trying to transmit SESSION attributes from one JSP to another, it works rather unstable ... may be I'm doing something wrong someone can correct me!!!
    sender.jsp
    <%session.setAttribute("test", "test"); %>
    receiver.jsp
    <% String test = (String)session.getAttribute("test"); %>
    ...

    I am trying to transmit SESSION attributes from one JSP to another, it works rather unstable ... may be I'm doing something wrong someone can correct me!!!
    sender.jsp
    <%session.setAttribute("test", "test"); %>
    receiver.jsp
    <% String test = (String)session.getAttribute("test"); %>
    ...

  • Session attribute is lost while going from one action to other action

    Hi All
    I am working on struts application. The problem that I am facing is my session attribute is losing. I am doing following steps.
    1. Setting some values in ActionForm (note this action form is in session scope for each action using it) from homepage.
    2. then submit the form and go to searchation.
    3. perform some task and set some values on actionform.
    4. click a link and get back to homepage using homeaction.
    5.change on value on homepage and again perform step -1.
    till step 4 value is retained fine but as soon as we perform 5th step the values got lost.
    please if anyone can expalin why is this happening ( I am using get method on homepage.jsp)

    Hey if someone can help me

  • Session is lost when going from a servlet to a jsp

    Any help would be greatly appreciated.
              I can sucessfully go from my jsp page to the Servlet. When in the servlet I have a service method where I place the information from my form on the jsp on a bean. Then I do a session.setAttribute("aBean", aBean) to place the bean in the session. Then do a req.sendRedirect("my.jsp"). Watching it in the debugger, when we leave the servlet our session is cleared and when we do a jsp:usebean to get the bean session from the session it creates a new bean so all the information is gone that was there before. here is my usebean tag where we are getting it from scope,
              <jsp:useBean id="aBean" scope="session" class="com.MyBean"></jsp:useBean>
              Thanks, Trucker

    <jsp:useBean name="helper" scope="session" class=".."/>
              <jsp:useBean name="helper" scope="session" type=".."/>
              ·class="package.class"
              Instantiates a bean from a class, using the new keyword and the class constructor. The class must not be abstract and must have a public, no-argument constructor. The package and class name are case sensitive.
              ·type="package.class"
              If the bean already exists in the scope, gives the bean a data type other than the class from which it was instantiated. The value of type must be a superclass of class or an interface implemented by class.
              If you use type without class or beanName, no bean is instantiate
              In your case you already instantiated the bean “com.MyBean” in servlet and you set bean in session scope. But you are not accessing that bean from servlet. Instead of that you are crating a new bean instance by using class attribute of <jsp: useBean>. So if you want to access the bean already created in servlet you should use type attribute instead of class in <jsp: useBean>. So you have to change your code as follows.
              <jsp:useBean id="aBean" scope="session" type="com.MyBean"></jsp:useBean>
              Then you will not lose the bean created in servlet.
              - Navaneeth

  • HELP: attributes saved in session got lost

    Hi, All:
    We have the following architecture:
    Client IE Browser Verison 6.0. --> Gateway
    --> Portal Server 6.0
    --> Sun One Web Server 6.0
    We have Portal server (http://portalURL) and Web Server (http://webserverURL) behind one Gateway (https://gatewayURL).
    One application is deployed on Sun One Web Server.
    After user login to Gateway/portal, user gets the default portal page https://gatewayURL/http://portalURL/defaultpage.jsp, the user then is redirected to A.jsp in Sun One Web Server https://gatewayURL/http://webserverURL/xyz/A.jsp.
    A.jsp saves variables in the session using:
    session.setAttribute("CLIENT_ID", "5" );
    Right after that, the user access the B.jsp in the Sun One Web Server by
    https://gatewayURL/http://webserverURL/xyz/B.jsp
    B.jsp tries to retrieve the varialble stored by A.jsp using:
    String clientId = (String)session.getAttribute("CLIENT_ID");
    But it fails, the clientId is null.
    What we find is that somehow a new HttpSession is created for every new request from same browser session, so A.jsp and B.jsp have different session.
    We are losing all the session attributes saved in the previous requests.
    however, there is no such problem with with Mozilla 1.7a - variables saved in session in A.jsp can be retrieved by B.jsp.
    Thanks.
    Joe Zhou

    Hello ,
    I have the same problem with the portal 6.2. The problem is for all browser.
    Have you solve the problem?
    Tia !!
    Bye Giovanni

  • Javascript to JSP question...Can javascript function set session attributes

    hello,
    i have a web app that, on one of its pages, displays "tabbed pane" as an image map at the top (a la amazon.com). my problem is this: each "logical" page contains separate forms that all use the same javabean. in other words, imagine that the tabs represent an account maintenance web ui for an on-line record store. the first tab might be labeled "General," the second "Contact info," the third "Shipping Info." Each uses the same account bean and displays portions of its properties relevant to the tab at hand. what i want to do is allow a user to enter the account maintenance ui, update info on the first tab, click on tab two and have the request with the changes sent to a processing jsp. yet, since each "tab" is actually a separate URL to another page, how do i get the updated info on the first tabe without adding some sort of "SAVE" button on each tab. ive considered using javascript, but dont know how to get the request params out of the first tab whn i click on another tab. is it possible to include an "onClick" function in each URL that "grabs" the updated form fields off the preceeding tab? can a javacript function set session attributes in jsp?

    hello there,
    wow, you've created one big mammy-jammy tool.
    first, javascript cannot access, set values to the session, without having to post to another JSP. javascript is great for manipulating objects, layers, form values, etc.
    you have 2 issues [if i understand correctly]:
    1) you need to able to save user info for a specific tab without having to reloading the page.
    ---you can create a form for EACH of your tabs and POST all the information to a hidden IFRAME or LAYER for NN4. that hidden IFRAME / LAYER will load a JSP page which with all the parameters you posted to it. or you can build a FRAMESET and target that document["frame-name"].src with that same JSP.
    2) handling when the SAVE INFO action should happen: hence some javascript event handler: onMouseOver, onClick, etc
    ---i don't know the dynamics of your tabs, but if store which tab was clicked on last, then if the user clicks on some other tab, javascript can submit that FORM to a JSP [see condition above]
    you have an interesting tool. can i see?
    i hope i wasn't too confusing, but your problem is sooo interesting. =)
    -WJP

Maybe you are looking for

  • 2 GB memory ample enough to handle iMovie tasks?

    Hello. I'm about to get a 2.33 GHz iMac with 2 GB memory. If any of discussion-board users have 2 GB memory, I'm curious if any of you find your machines locking up or not up to the task of handling iMovie projects in any way. Yea, yea: I know: More

  • Sales order upload using bapi

    Hi, Thanks in advance I need step by step procedure to create sales orders using BAPI from a text file

  • How to unlock the portal Contents

    Hi All, Please say me the Procedure to unlock the Portal Contents which are already locked by me Thanks in Advance

  • Mapping error in nativeQuery

    I have such query:      StringBuilder sb = new StringBuilder();           sb.append("select I.ID as id, I.TITLE as institutionTitle, R.TITLE as regionTitle,F.TITLE as fedTitle,F.ORDER as fedOrder,count(distinct(P.ID)) as count");           sb.append(

  • CF: Checkpoxes in Report builder

    Hallo, ich versuche im Report Builder einen recht komlexen Report (Format= Excel) zu erstellen. Dabei möchte ich leere Checkboxes erstellen, die ich dann später im Excelreport markieren bzw. entmarkieren kann. Wie in einem in Excel erstellten Formula