Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Expression Language

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i was wrong!!!
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Thanks. Venkat.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben and Paul for the valuable information.

reply
    Bookmark Topic Watch Topic
  • New Topic