• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.setAttribute() arguments

 
shanthisri mocherla
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I just want to know
Is this the correct syntax.??

request.setattribute("Genre","Ambient");
I think in setAttribute() method, the first argumnet is a String and the second argumnet is an expression.

and one more question on EL.

In this statement ${musicList[0]} .Do we have to keep the first element(at index 0) of either List or Array without qoutes???or Is it okay if we keep
quotes around 0.
Like this ${musicist["0"]}.

Thnak you very much
Shanthi
 
Sai Patnala
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Second argument in ServletRequest.setAttribute is object. What you passed will work because String object is passed in.

For integer literal index for this EL Expression, both ${musicList[0]} and ${musicList["0"]} are same.

But if you are using expression in place of index, if that expression is a valid attribute, that gets evaluated not the expression. HFSJ has good examples on this.

Hope this helps. May be someone can give better explanation on second one!
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In this statement ${musicList[0]} .Do we have to keep the first element(at index 0) of either List or Array without qoutes???


Not necessarily. It can even be ${musicList[5]}.


Is it okay if we keep
quotes around 0.
Like this ${musicList["0"]}.


Sure. But "musicList" has to be an array/List. It can't be a Map/Bean. Here the string "0" is turned into an int 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic