You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Becker <CB...@cablevision.com> on 2005/12/07 03:00:02 UTC

accessing request attributes

I am setting request attributes in an Action class such as in the
following example:
 
            request.setAttribute("toDate", toDate);
            request.setAttribute("acctNum", acctNum);

Both variables toDate and acctNum are Strings. I then process the
action by returning a mapping.findForward to a JSP page.
 
I wish to be able to access these attributes as scripting variables on
my JSP page, and display their values if they happen to have them (e.g
not empty String or null, which could be possible).
 
My question - how do you access request attributes with Struts tags and
make them available as scripting variables?
 
I have tried using <bean:define>, but have been unsuccessful.
 
Any guidance or help would be appreciated... thanks!
 
--Chris

Re: accessing request attributes

Posted by atta-ur rehman <at...@gmail.com>.
Chris,

I'm sure you'd know scriplet way of doing it, which I'm not going to
recommend: <%=request.getAttribute("toDate") %>.

Struts' bean:write should do it: <bean:write scope="request" name="toDate"/>

Better still if you're using Servlet 2.4 compliant app server/servlet
container you could use JSTL expressions: ${toDate} and it will search the
attribute in app, session, request and page scope for you. Same thing as
<c:out value="${toDate}"/>. You'd, of course, need to include TLDs for JSTL
in the latter case.

Hope this helps.

ATTA



On 12/6/05, Christopher Becker <CB...@cablevision.com> wrote:
>
> I am setting request attributes in an Action class such as in the
> following example:
>
>             request.setAttribute("toDate", toDate);
>             request.setAttribute("acctNum", acctNum);
>
> Both variables toDate and acctNum are Strings. I then process the
> action by returning a mapping.findForward to a JSP page.
>
> I wish to be able to access these attributes as scripting variables on
> my JSP page, and display their values if they happen to have them (e.g
> not empty String or null, which could be possible).
>
> My question - how do you access request attributes with Struts tags and
> make them available as scripting variables?
>
> I have tried using <bean:define>, but have been unsuccessful.
>
> Any guidance or help would be appreciated... thanks!
>
> --Chris
>
>