Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL  RSS feed

 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I am trying to use jstl in my jsp.
Below is the code i wanted in jstl form.

I am trying to put this in jstl tag.

I am not able to use charAt the way i have mentioned above.
Is there any other solution for this.

Any help may be appreciated.
Thanks in advance.
Ramya
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite correct, you can't call java methods like that. EL can only access the getters/setters of an object.

What are you trying to accomplish this for? It might be easier to encapsulate the data in an object.
For instance, if you have a username, and you are wanting to get the first initial of their name then provide two methods on a user object:
getFirstName()
getInitial().

The implementation of getInitial might just return getFirstName().charAt(0);
In JSTL you could then use ${user.firstName}, ${user.initial}

The alternative if you have a JSP2.0 container and can use JSTL1.1 is to use a function.
note: Your first set statement was incorrectly translated from the original java. You should not use the ${ } around a static value.



Cheers,
evnafets
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
That was really helpful
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!