• Post Reply Bookmark Topic Watch Topic
  • New Topic

EL and Scriptlets in jsp

 
Amit Singh Hora
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i was just playing around using El in javascript and Scriptlets in a jsp ,But not able to figure out the following

Code in JSp




Help me in understanding this behaviour
 
Devaka Cooray
Marshal
Posts: 5174
490
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Singh Hora wrote:pop up the value 1,But when used like alert('${serverArray[0]}')--->will not give anything


EL doesn't work in that way. EL expressions are intended to work with scoped variables and implicit objects. Given that serverArray is neither scoped nor an implicit object, EL processor won't be able to trace down to serverArray variable. Note that EL is there to replace scriptlets - using them together is pointless.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the JSTL And EL and ditch scriptlets completely. They do not work together and trying to make them do so will just create a big old mess.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL variables are the attributes in context in the JSP.
So to make your local java variable accessible via EL:



 
Devaka Cooray
Marshal
Posts: 5174
490
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make it more clarify, the above approach don't make EL engine access the initial variable directly. Instead, it gets referenced in a page scoped attribute with the same name as the initial variable name, and that's what doing the illusion.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still, don;t mix the EL with scriptlets. That's a hot mess.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!