This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes jstl ..c:set  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl ..c:set  " Watch "jstl ..c:set  " New topic
Author

jstl ..c:set

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
I am new to jstl..pls. help..



Can I set the value of a string variable in <c:set ?

if yes. give any example.

Regards,
Neeraj.
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Hi,

Using <c:set> we can store values and object and also in different scope.
some examples,
<c:set var="place" value="Chennai"/>
<c:set var="name1" value="value1" scope="page" />
<c:set var="com_mycompany_name2" value="value2" scope="request" />
<c:set var="com_mycompany_name3" value="value3" scope="session" />
<c:set var="com_mycompany_name4" value="value4" scope="application" />
[ October 19, 2005: Message edited by: Raghu Shree ]

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
hi,

thnx for the inputs.. but I want something like this..

<%
String strCity="xyz";
%>

and assign this variable in value like

<c:set var="home" value="<%= strCity %>" scope="session"/>

but this is not working...need some other way of doing it..

Regards,
Neeraj.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
hi,

thnx for the inputs.. but I want something like this..

<%
String strCity="xyz";
%>

and assign this variable in value like

<c:set var="home" value="<%= strCity %>" scope="session"/>

but this is not working...need some other way of doing it..

Regards,
Neeraj.
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Hi,
Try like this
<%
String strCity="XYZ";
pageContext.setAttribute( "city", strCity);
%>

then

<c:set var="home" value="<%= strCity %>" scope="session"/>

(or)

<c:set var="home" value="${strCity}" scope="session"/>

Hope this will helps you.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
thnx again..

I have trying out this sample

<%
String name="neeraj";
pageContext.setAttribute("name1",name);
%>
name1:<c ut value="${name1}" />
<br>


<c:choose>
<c:when test ="${name1 eq 'neeraj'}">
HELLO &&&&

</c:when>
</c:choose>

I am getting this error.. I am unable to debug it..
org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
Syntax error, insert "Finally" to complete TryStatement

Generated servlet error:
Syntax error on token "catch", Identifier expected

Generated servlet error:
out cannot be resolved

Generated servlet error:
_jspx_out cannot be resolved

Generated servlet error:
out cannot be resolved

Generated servlet error:
out cannot be resolved

Generated servlet error:
out cannot be resolved

Generated servlet error:
_jspx_page_context cannot be resolved

Generated servlet error:
_jspx_page_context cannot be resolved

Generated servlet error:
Syntax error on token "finally", { expected

Generated servlet error:
_jspxFactory cannot be resolved

Generated servlet error:
_jspxFactory cannot be resolved

Generated servlet error:
_jspx_page_context cannot be resolved
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Hi,
To sort out the propbelm remove all jstl tags except the follwing.
<%
String name="neeraj";
pageContext.setAttribute("name1",name);
%>
name1:<c ut value="${name1}" />
<br>

If the error agin occurs give me your whole jsp file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl ..c:set
 
Similar Threads
Where's the best place to declare all the beans?
bean:define not working in logic:iterate
Passing values between JSTL and scriptlet
How to set value in JSTL
Passing values between JSTL and scriptlet