• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Question

 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple code in my JSP

String[] favouriteMusic = {"Kutch Kutch Hota Hai","Mohabatein"};
${favouriteMusic[0]}

what will be the output in my JSP ???

Thanx in advance

sanjay
 
Radmika Arunachalam
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wont print anything.. It will check for "favouriteMusic" in page scope.. since it is not stored in that scope.. result is empty
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
It means
1) It will look for attribute in page,request,session and application scope
Am i right ???.
2)As i have read in hfsj that first value on lefside

i.e musicList["0"] is either
1)bean
2)map
3)array
4)List

So then why it will not get printed at output ???

Please reply me back.And thanx in advance

-SAnjay
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
String[] favouriteMusic = {"Kutch Kutch Hota Hai","Mohabatein"};
%>

${favouriteMusic[0]}

--> Will not output, since the favouriteMusic is not in any scope attributes.



This should work:
<%
String[] favouriteMusic = {"Kutch Kutch Hota Hai","Mohabatein"};
pageContext.setAttribute("favouriteMusic", favouriteMusic);
%>
 
Olivier Cleyman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They also said:

The first named variable in the expression is either an IMPLICIT OBJECT or an ATTRIBUTE.

Hope it helps...


Hi
It means
1) It will look for attribute in page,request,session and application scope
Am i right ???.
2)As i have read in hfsj that first value on lefside

i.e musicList["0"] is either
1)bean
2)map
3)array
4)List

So then why it will not get printed at output ???

Please reply me back.And thanx in advance

-SAnjay

--------------------

Eat JAVA, Drink JAVA, Sleep Java
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Just modifying the question a little

If we have some variable in a scriptlet

<% String userName = "Admin"; %>

Is there any way to acccess this in the same JSP using EL or JSTL without
setting as an attribute in any of the scopes

Thanks
Shiva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic