Solved

int returned by session

Posted on 2004-04-26
2
388 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now