| Author |
Expression Language
|
Jetendra Ivaturi
Ranch Hand
Joined: Feb 08, 2007
Posts: 159
|
|
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.
|
SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
sorry i was wrong!!!
|
 |
Jetendra Ivaturi
Ranch Hand
Joined: Feb 08, 2007
Posts: 159
|
|
Ben... Its not clear Ben. Am new to this, could you explain it again. Thanks.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Feb 08, 2007
Posts: 159
|
|
|
Got it, any idea how to retrieve the variable using pageContext scope
|
 |
Jetendra Ivaturi
Ranch Hand
Joined: Feb 08, 2007
Posts: 159
|
|
Hi Venkat But SCWCD book haven't discussed about this. Any idea. Thanks.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Feb 08, 2007
Posts: 159
|
|
|
Ok. Thanks. Venkat.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
|
Thanks Ben
|
 |
Paul Yule
Ranch Hand
Joined: May 12, 2008
Posts: 229
|
|
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
Joined: Feb 08, 2007
Posts: 159
|
|
Thanks Ben and Paul for the valuable information.
|
 |
 |
|
|
subject: Expression Language
|
|
|