This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
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

Expression Language  RSS feed

 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am unable to see the output for the following code:

<! int i=100;%>
${i}

I have written this in JSP. Have deployed this.

I mean to say do I have to do any setting so as to display the EL elements.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL is not designed to see instance variables (scriptlets and EL should not be mixed).

If you want the variable to be visible to EL, bind it to one of the scope objects.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jetendra Ivaturi:

<! int i=100;%>
${i}

I have written this in JSP. Have deployed this.





Hi Jetendra write int i=100 in servlet then forward to jsp there ${i}
now you can see the output

i.e servlet--- int i=100;
jsp------- ${i}
// EL just show the value of variable which is on controller(backend)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i was wrong!!!
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben...

Its not clear Ben. Am new to this, could you explain it again.

Thanks.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi... try this in your jsp
----------------
<%String i="8"; request.setAttribute("key", i); %>
${key} //wat you want
---------------------------------------
Ben said that you have to bind your variable to any of scope ..here i am using request//request.setAttribute("key", i);
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, any idea how to retrieve the variable using pageContext scope
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venkat

But SCWCD book haven't discussed about this.

Any idea.

Thanks.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jetendra Ivaturi:

SCWCD book haven't discussed about this.



yes.directly they did not give...
--------------------------------------
just use pageContext instead of request .
----------------------------------------
note: using pageContext you can access any of the scopes
example session=pageContext.getSession()..etc
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks. Venkat.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure books wouldn't talk about how to do this because JSTL, EL, and the architecture required to use them correctly are meant to be a replacement to scriptlets; not an addition to them.

Since you've made this value static, I assume you want it to be the same for every object that uses it and that you want it to last for the lifetime of the app so context scope would be your best bet.




EL searches the various scope objects to find variables.
It doesn't look in the JSP page itself.
Generally, if you need to do something like this, you're not using JSTL, or EL as intended.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:

Generally, if you need to do something like this, you're not using JSTL, or EL as intended.


http://www.ociweb.com/jnb/jnbSep2003.html
Article for supporting this reasoning and examples of proper use.
[ June 25, 2008: Message edited by: Paul Yule ]
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben and Paul for the valuable information.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!