Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL pageScope  RSS feed

 
Goldie Fernandes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I dunno if this question has already been asked. If it has, will you pls direct me to that post?
The following code sets a variable 'str' and correctly outputs: "yoohoo"
<c:set var="str" scope="page" value = "yoohoo" />
<c ut value = "${pageScope.str}" default = "null" />
-----------------------------------------
But the following code outputs the default value "null"
I even removed the forced reference to the page scoped .. i.e. just ${str} and it still dint work
Could you pls tell me why? I thought that the scriplet sets a variable str in page scope just like the <c:set> tag
<%
String str = new String ("yoohoo");
%>
<c ut value = "${pageScope.str}" default = "null" />
Environment used: JBuilder6.0 on Tomcat 4
Thanks!
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page-scoped attributes are different from scripting variables. There is no way for a JSP tag to read local scripting variables. If you want to expose a scripting variable as an attribute you'll need to do so explicitly, as with
<% pageContext.setAttribute("str", str); %>
JSTL's design encourages you to avoid scripting variables in the first place and use scoped attributes instead, initially.
Hope that helps!
 
Goldie Fernandes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shawn,
Thanks for your reply!! Really helped.
Guess i should go for your book!
Have a nice day.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!