Link to home
Start Free TrialLog in
Avatar of mskim100
mskim100

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OR:

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


then:

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