This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Limit length of characters output in JSP string  RSS feed

 
Tenley Baldwin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am outputting a string from a java bean and want to limit the number of characters. How can I do that? Here is the code I have in the JSP
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best place to do that would be within the bean, not the JSP. Keep the JSP as simple as possible.
 
Tenley Baldwin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that makes sense. At first I was thinking that wouldn't work because I was using the same bean for another JSP page where the full length will be displayed, but this page is called with an if statement, so just need to put the truncate in the if statement. I'm still having trouble with that. I've tried making a method to do the truncating, but am having two problems with that. First is I'm working with a vector list, having trouble getting the string out of there, and then what to return to the request which is forwarded to the JSP. Below is my code, List.jsp is the one I want to limit the length in



And here's the bean
 
Tenley Baldwin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a JSTL function to do this for me instead of writing one myself and that is working exactly as desired, however in the process I found that the back button doesn't work. Everything looks fine that I can see, just loads a blank page each time though. I tried submitting via GET as well so it should load exactly as when the server is initially loaded, but it's not working either way. Below is the new code

JSP


Servlet
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!