You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2003/12/08 03:37:00 UTC
Pass A String From Servlet And Write Out Its Value in JSP
My servlet has a String called 'category'. I want to
pass the String to a JSP. Therefore, I have the code
shown below in the servlet:
session.setAttribute( "c", category );
OR
request.setAttribute( "c", category );
And, I do the following in my JSP:
<% String keyValue = (String)session.getAttribute( "c"
); %>
OR
<% String keyValue = (String)request.getAttribute( "c"
); %>
How do I write out keyValue in my JSP in Struts?
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Pass A String From Servlet And Write Out Its Value in JSP
Posted by Brice Ruth <br...@fiskars.com>.
The easiest way to do this isn't with a Struts tag, per se, but with a
JSTL tag, I think - just use the JSTL 1.0 (or 1.1) tag library like so:
<% taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:out value="${c}"/>
That *should* work for either a session-scoped variable or a
request-scoped variable.
If you need to print out a value from a scriptlet (which is where
keyValue is being defined) - you should store that value in pageContext,
like so:
<%
pageContext.setAttribute("keyValue", keyValue); // first parameter can
be anything you want to name it
%>
<c:out value="${keyValue}"/>
That should be it!
Caroline Jen wrote:
>My servlet has a String called 'category'. I want to
>pass the String to a JSP. Therefore, I have the code
>shown below in the servlet:
>
>session.setAttribute( "c", category );
>OR
>request.setAttribute( "c", category );
>
>And, I do the following in my JSP:
>
><% String keyValue = (String)session.getAttribute( "c"
>); %>
>OR
><% String keyValue = (String)request.getAttribute( "c"
>); %>
>
>How do I write out keyValue in my JSP in Struts?
>
>
>__________________________________
>Do you Yahoo!?
>New Yahoo! Photos - easier uploading and sharing.
>http://photos.yahoo.com/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
--
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org