Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of [] in EL - Doubt

 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to validate the below statement through an example:
If there is no quotes against the variable inside [], then container tries to find an attribute with that name and get its value and use that value as the map�s key or the bean�s property.

My servlet code had the following line:

req.setAttribute("test1","value1");
req.getRequestDispatcher("/jsp/ELDemoJsp.jsp").forward(req,res);


My JSP tried the following:

requestScope.mani -> ${requestScope.mani} <br>
requestScope["mani"] -> ${requestScope["mani"]}<br>
requestScope[mani] -> ${requestScope[mani]}<br>


My Output showed:

requestScope.test1 -> value1
requestScope["test1"] -> value1
requestScope[test1] ->


I was not able to get "value1" for the third EL ... why?

Is this rule applicable only for Maps/Lists and Arrays ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I think you misstypes mani for test1)

requestScope[test1] will look for "value1" in the request.
try :
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Yes! Sorry about that Mistake!

And yes! What you said worked ... Was a bit confused and now it is clear!

Thanks!
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Yes! Sorry about that Mistake!

And yes! What you said worked ... Was a bit confused and now it is clear!

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