u need to do the following things
firstly when u store the session value in the string variable, u need to
type cast it to string, i.e.,
String accesslevel;
accesslevel = (String)session.getAttribute("Access");
first check whether in the page where u r setting the session value, u r
using setAttribute method or setValue method
accordingly u have to use the get method, i.e., getAttribute or getValue
in both the cases u have to typecast it to String
secondly when u r comparing it to Administrator, use the following code:
if(accesslevel.equals("Administrator"){
}else{
}
also when u r retrieving the value of the session check it in the following
manner:
if(session.getAttribute("Access")!=null){
accesslevel = (String)session.getAttribute("Access");
}else{
redirect to the login page or the page where u r setting the session
}
if u dont check whether the session is null or not n directly typecast it to
string then it will fire a NullPointerException
hope this helps u
regards
prashant
Age does not protect you from love. But love, to some extent, protects you
from age. - Jean Moreau
> -----Original Message-----
> From: Al Higgs [SMTP:al.higgs@b...]
> Sent: Friday, March 01, 2002 12:50 AM
> To: Pro_JavaServer_Pages
> Subject: [pro_jsp] Problems with Sessions!
>
> Hello,
>
> Im new to JSP and I seem to be having some problems with sessions, ill
> quickly explain the problem.
>
> On a page i have set a session called "user", which has got an
> attribute called "Access". What i want to do is define whether that
> attribute is equal to "Administrator". If it is i want to show a form, if
>
> not show some error message. But storing the value into a string seems to
>
> be giving problems.
>
> However i can display the value of "Access" if i use
>
> <%=session.getAttribute("Access")%>
>
> So why doesnt the following work??
>
> <%
> String accesslevel;
> accesslevel = session.getAttribute("Access");
>
> if (accesslevel != "administrator")
> {
> out.print("Show Administrator Stuff Here");
> }
> else
> {
> out.print("Show non Administrator Stuff instead");
> }
> %>
>
> I really appreciate any input
>
> Thanks
>
> Al