[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

int returned by session

well, it seems that i'm having real hard time working with integers in jsp.

i set a variable, ie. uid = "100", and i do use quotes since the program was yelling at me.  but when i try to get it back in another jsp page, it wont let me cast it to an integer.

so setting my session:
=======================================================
<%@ page import="java.io.*, java.sql.*, java.util.*, java.lang.*" %>
<%@ page import="javax.naming.directory.*, javax.naming.*, javax.servlet.http.HttpSession, javax.servlet.jsp.*" %>

<%
...
        try {
...
                    if (knownURL.equals(awsAppentryURL)) {
                        out.println("<p>Legal: Token Matched!</p>");
// set sessions here
                        session.setAttribute("calSID",awsUid);
                        out.println("SID session: " + session.getAttribute("UID"));

//user level
//                      only students get their access here. so set the user access level to 0
                        session.setAttribute("UserLevel","0");
//===i tried to set this attribute with 0 without quotes but it wouldn't let me.===
                        out.println("cal access level session: " + session.getAttribute("UserLevel"));

                        out.println("session creation time: " + session.getCreationTime());
//===i get everything printed on screen===
                    } else {
                       out.println("Illegal Access! The Tokens did not match!");
                   }
                  }
               
            } catch (IOException e) {
                throw new JspTagException("I/O Exception, " + e );
            }
        } catch (Exception e) {
            throw new IOException("Exception, " + e);
        }
    }

%>
======================================================
and i can print out all the sessions.  so trying to use them in my other jsp page:
========================================================
<%@ page import="java.util.*..." %>
<%
out.println("what's my sid here? " + session.getAttribute("UID"));
out.println("what's my user level here? " + session.getAttribute("UserLevel"));
//==it prints but it'll blow up below==
Integer uAccessLevel = (Integer)session.getAttribute("UserLevel");
%>
========================================================
please, appreciate any help!

mskim100
0
mskim100
Asked:
mskim100
  • 2
1 Solution
 
bobbit31Commented:
Integer uAccessLevel = new Integer((String) session.getAttribute("UserLevel"));
0
 
bobbit31Commented:
OR:

session.setAttribute("UserLevel",new Integer(0));


then:

Integer uAccessLevel = (Integer)session.getAttribute("UserLevel");
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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