You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by struts <st...@pandora.be> on 2003/12/05 14:40:14 UTC

session taglib

In the Jsp i have:

<sess:attribute name="userName"/>

witch prints the username. Now i want something like:

<%

String username= <sess:attribute name="userName"/>;

%>

but that doesn't work. How can i assign the session variable to the String username ?

Thanks !



Re: session taglib

Posted by Suneel Kumar Kollukuduru <su...@collab.net>.
<bean:define id = "user" name = "userName" scope = "session" toScope = 
"session" type = "java.lang.String" />


struts wrote:

>In the Jsp i have:
>
><sess:attribute name="userName"/>
>
>witch prints the username. Now i want something like:
>
><%
>
>String username= <sess:attribute name="userName"/>;
>
>%>
>
>but that doesn't work. How can i assign the session variable to the String username ?
>
>Thanks !
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by James Mitchell <jm...@apache.org>.
On Fri, 5 Dec 2003, Oron Gill Haus wrote:

> James,
>
> Isn't there a drive to move to JSTL vs. the Struts tag library?  I'm
> curious as we've been pushing JSTL for this reason (though it rather
> flexible).

Yes, you are absolutely correct.  Use c:set if you can (given the min spec
requ).

Have a good one!

>
> Thank you.
>
> --- James Mitchell <jm...@apache.org> wrote:
> > On Fri, 5 Dec 2003, struts wrote:
> >
> > > In the Jsp i have:
> > >
> > > <sess:attribute name="userName"/>
> > >
> > > witch prints the username. Now i want something like:
> > >
> > > <%
> > >
> > > String username= <sess:attribute name="userName"/>;
> > >
> > > %>
> > >
> > > but that doesn't work. How can i assign the session variable to the
> > String username ?
> >
> > A scriptlet-free way to do this:
> >
> > <bean:define id="username">
> >  <sess:attribute name="userName"/>
> > </bean:define>
> >
> > >
> > > Thanks !
> > >
> > >
> > >
> >
> > --
> > James Mitchell
> > Software Developer / Struts Evangelist
> > http://www.struts-atlanta.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> =====
> Oron Gill Haus
> IBM CSE Content Manager 8 - Sun Certified Programmer Java 2 1.4
> office: (410) 539-3733 x1348
> fax:    (410) 837-9535 c/o Oron
> e-mail: ohaus@comcast.net
> web: http://www.electronicscene.com/oron_haus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

-- 
James Mitchell
Software Developer / Struts Evangelist
http://www.struts-atlanta.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by Oron Gill Haus <or...@yahoo.com>.
James,

Isn't there a drive to move to JSTL vs. the Struts tag library?  I'm
curious as we've been pushing JSTL for this reason (though it rather
flexible).

Thank you.

--- James Mitchell <jm...@apache.org> wrote:
> On Fri, 5 Dec 2003, struts wrote:
> 
> > In the Jsp i have:
> >
> > <sess:attribute name="userName"/>
> >
> > witch prints the username. Now i want something like:
> >
> > <%
> >
> > String username= <sess:attribute name="userName"/>;
> >
> > %>
> >
> > but that doesn't work. How can i assign the session variable to the
> String username ?
> 
> A scriptlet-free way to do this:
> 
> <bean:define id="username">
>  <sess:attribute name="userName"/>
> </bean:define>
> 
> >
> > Thanks !
> >
> >
> >
> 
> -- 
> James Mitchell
> Software Developer / Struts Evangelist
> http://www.struts-atlanta.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


=====
Oron Gill Haus
IBM CSE Content Manager 8 - Sun Certified Programmer Java 2 1.4
office: (410) 539-3733 x1348
fax:    (410) 837-9535 c/o Oron
e-mail: ohaus@comcast.net
web: http://www.electronicscene.com/oron_haus

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by James Mitchell <jm...@apache.org>.
On Fri, 5 Dec 2003, struts wrote:

> In the Jsp i have:
>
> <sess:attribute name="userName"/>
>
> witch prints the username. Now i want something like:
>
> <%
>
> String username= <sess:attribute name="userName"/>;
>
> %>
>
> but that doesn't work. How can i assign the session variable to the String username ?

A scriptlet-free way to do this:

<bean:define id="username">
 <sess:attribute name="userName"/>
</bean:define>

>
> Thanks !
>
>
>

-- 
James Mitchell
Software Developer / Struts Evangelist
http://www.struts-atlanta.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by Gurpreet Dhanoa <gu...@smartdatainc.com>.
hi

Try

String username=(String)session.getAttribute("username");

You have explicitly cast it into String as it is Serialized.


Regards
Gary

----- Original Message -----
From: "John Ferguson Smart" <jf...@aacom.fr>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 05, 2003 7:13 PM
Subject: Re: session taglib


> Try something like
>     String username = session.getAttribute("username");
> or
>     String username = request.getSession(à.getAttribute("username");
>
>
> struts wrote:
>
> >In the Jsp i have:
> >
> ><sess:attribute name="userName"/>
> >
> >witch prints the username. Now i want something like:
> >
> ><%
> >
> >String username= <sess:attribute name="userName"/>;
> >
> >%>
> >
> >but that doesn't work. How can i assign the session variable to the
String username ?
> >
> >Thanks !
> >
> >
> >
> >
> >
> >
>
> --
> John Ferguson Smart, PhD
> Directeur de Projet
> Département informatique Communicante
> AACOM
> email : jfsmart@aacom.fr
>
> ---------------------------------------------------------------------
> AACOM - L'Informatique communicante
> 120 rue du Marin Blanc - Z.I. des Paluds
> 13685 Aubagne Cedex
> tel : 04.42.72.65.69 - fax : 04.42.72.65.68
> Web : http://www.aacom.fr
> ---------------------------------------------------------------------
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by John Ferguson Smart <jf...@aacom.fr>.
Try something like
    String username = session.getAttribute("username");
or
    String username = request.getSession(à.getAttribute("username");


struts wrote:

>In the Jsp i have:
>
><sess:attribute name="userName"/>
>
>witch prints the username. Now i want something like:
>
><%
>
>String username= <sess:attribute name="userName"/>;
>
>%>
>
>but that doesn't work. How can i assign the session variable to the String username ?
>
>Thanks !
>
>
>
>
>  
>

-- 
John Ferguson Smart, PhD
Directeur de Projet
Département informatique Communicante 
AACOM
email : jfsmart@aacom.fr

---------------------------------------------------------------------
AACOM - L'Informatique communicante
120 rue du Marin Blanc - Z.I. des Paluds
13685 Aubagne Cedex
tel : 04.42.72.65.69 - fax : 04.42.72.65.68
Web : http://www.aacom.fr
---------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by Oron Gill Haus <or...@yahoo.com>.
You can use JSTL to accomplish this using the:

<c:set var="username" value="${username}" />

You can also specify the scope within the value expression.  This is if
you wish to use JSTL.  Only a suggestion.  Hope it helps you out!

--- struts <st...@pandora.be> wrote:
> In the Jsp i have:
> 
> <sess:attribute name="userName"/>
> 
> witch prints the username. Now i want something like:
> 
> <%
> 
> String username= <sess:attribute name="userName"/>;
> 
> %>
> 
> but that doesn't work. How can i assign the session variable to the
> String username ?
> 
> Thanks !
> 
> 
> 


=====
Oron Gill Haus
IBM CSE Content Manager 8 - Sun Certified Programmer Java 2 1.4
office: (410) 539-3733 x1348
fax:    (410) 837-9535 c/o Oron
e-mail: ohaus@comcast.net
web: http://www.electronicscene.com/oron_haus

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: session taglib

Posted by Scott Reisdorf <re...@llnl.gov>.
You are using a Tag Lib within a Scriptlet.
You can assign the variable using the scriplet by the following:

<%
String username = (String) session.getAttribute("userName");
%>

hope that helps.
-scott

At 02:40 PM 12/5/2003 +0100, you wrote:
>In the Jsp i have:
>
><sess:attribute name="userName"/>
>
>witch prints the username. Now i want something like:
>
><%
>
>String username= <sess:attribute name="userName"/>;
>
>%>
>
>but that doesn't work. How can i assign the session variable to the String 
>username ?
>
>Thanks !



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org