• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Not getting session value????

My code below always shows the "nfsu2SelectedPlatform" as being nulll?  If I check after the conditionals, it is set but when I reload the page, it is null again???? What am I doing wrong???

------------------------------------------------------------------------------------

<%
    HttpSession sessionObject = request.getSession(true);
    String nfsu2SelectedPlatform = (String)sessionObject.getValue("nfsu2SelectedPlatform");
      String platform = request.getParameter("platform");
      
        %>nfsu2SelectedPlatform will be null here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%

      if (nfsu2SelectedPlatform == null) {
        request.setAttribute("nfsu2SelectedPlatform", "ps2");
            platform ="ps2";
      } else if ((!(nfsu2SelectedPlatform.equals(platform)))&&(!(platform.equals("null")))){
            request.setAttribute("nfsu2SelectedPlatform", platform);
            platform = nfsu2SelectedPlatform;
    } else {
            platform = "test";
    }

%>nfsu2SelectedPlatform will be VALID here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%
      
%>
0
894359
Asked:
894359
  • 3
  • 3
1 Solution
 
894359Author Commented:
FYI.. I have also tried changing " request.setAttribute" to "sessionObject.setAttribute" !
0
 
objectsCommented:
does your request include nfsu2SelectedPlatform?
what does your form look like?  It needs to contain an attribute named nfsu2SelectedPlatform

0
 
894359Author Commented:
Or if this makes it easier to read:

------------------------------
<%
    HttpSession sessionObject = request.getSession(true);
    String nfsu2SelectedPlatform = (String)sessionObject.getValue("nfsu2SelectedPlatform");
     String platform = request.getParameter("platform");
      
       %>nfsu2Selected value NOT valid here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%
     
    request.setAttribute("nfsu2SelectedPlatform", "ps2");
         

%>nfsu2Selected value valid here: <%=request.getAttribute("nfsu2SelectedPlatform")%>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
Looks like your request simply does not include an attribute named 'nfsu2SelectedPlatform'.

The sessions does not appear to have anything to do with it as the following line is displaying the value from the request and *not* the session.

     %>nfsu2Selected value NOT valid here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%

Are you sure that shouldn't be:

     %>nfsu2Selected value NOT valid here: <%= nfsu2SelectedPlatform %> <%


0
 
894359Author Commented:
Please clarify something for me, how do I write to the session and get from the session then???
0
 
objectsCommented:
to add ad attribute to the session yopu use:
   session.setAttribute(name, value)
to get an attribute from session you use:
   session.getAttribute(name)
0
 
somasekharCommented:
<%
    HttpSession sessionObject = request.getSession(true);
    String nfsu2SelectedPlatform = (String)sessionObject.getAttribute("nfsu2SelectedPlatform");
     String platform = request.getParameter("platform");
     
        %>nfsu2SelectedPlatform will be always null here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%
nfsu2SelectedPlatform will be null here firs time : <%=sessionObject.getAttribute("nfsu2SelectedPlatform")%>

     if (nfsu2SelectedPlatform == null) {
        request.setAttribute("nfsu2SelectedPlatform", "ps2");
sessionObject.setAttribute("nfsu2SelectedPlatform", "ps2");
          platform ="ps2";
     } else if ((!(nfsu2SelectedPlatform.equals(platform)))&&(!(platform.equals("null")))){
          request.setAttribute("nfsu2SelectedPlatform", platform);
          platform = nfsu2SelectedPlatform;
    } else {
          platform = "test";
    }

%>nfsu2SelectedPlatform will be VALID here: <%=request.getAttribute("nfsu2SelectedPlatform")%> <%
     
%>
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now