• Post Reply Bookmark Topic Watch Topic
  • New Topic

<c:set> is not working as expected

 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written two jsp files.

index.jsp which looks as follows



and I have wrtten showfirst.jsp

the code is as follows


Person and Dog are two bean classes in the model package.



The problem is the <c:set var="fido" value="${person.dog.name}}/> is not working properly. Instead of showing the updated value in the lated part of index.jsp i.e "Zero", it still displays "Fido".

Whether my undertsnading of this is right or wrong? That is the question. If it is wrong what is the right way of doing it

Please help me solve this problem.

regards

Anil Deshpande>
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are assigning the value of ${person.dog.name } to a page scoped variable named 'zero'

So, ${zero } would output the dog's name.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${zero } would output the dog's name.


I didn't get you. "Fido" is the initial name of the dog.

Now I want it to be "Zero".

That is why I am writing it as <c:set var="zero" value="${person.dog.name}"/>. Is it Wrong?


I did the changes as suggested by you. But nothing is happening.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I think this is something that you generally should not really be doing inside a jsp.
Also <c:set> is working as expected... it's just you expect it to work differently.
Try this:


Sean
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anil Deshpande wrote:Now I want it to be "Zero".

That is why I am writing it as <c:set var="zero" value="${person.dog.name}"/>. Is it Wrong?

What does the JSTL Specification have to say about this? Are you using <c:set> correctly?
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:set> is working as expected... it's just you expect it to work differently.


Yes, I got it. Sean Clark is right. Thanks a lot man. Cleared lot of doubts of mine.

Thanks a lot
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Stuff.

I recommend you keep the jstl api bookmarked as it is a useful place to start if you have problems in the future.

Sean

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!