Search code examples
javajspstrutsjstl

<bean:write> tag for limiting the size of returned string


I am using following tag for showing comments on jsp, now I want to show only first 10 character of comments...

Example: "This is very urgent please provide details" Then <bean:write> should write only "This is ver......"

is there any way to achieve it, <bean:write name="order" property="ordercomments" />


Solution

  • You could easily do that using the JSTL fn:substring function, combined with the c:out tag to make sure propert HTML escaping is done :

    <c:out value="${fn:substring(someBean.someProperty, 0, 10)}" />
    

    See http://download.oracle.com/javaee/1.4/tutorial/doc/JSTL3.html for a tutorial.