Solved

int returned by session

Posted on 2004-04-26
2
390 Views
Last Modified: 2010-04-01
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
Comment
Question by:mskim100
  • 2
2 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 250 total points
ID: 10923020
Integer uAccessLevel = new Integer((String) session.getAttribute("UserLevel"));
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 10923022
OR:

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


then:

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Troubleshooting common task sequence error codes
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question