Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP String formatting Truncate

Tags:

java

string

jsp

Does anyone know how to truncate a string in a JSP using a tag library? I was going to use Jakarta Taglibs but it says that it has been retired because:

With the advent of JSTL, the core features of many of the libraries had been standardized and the need for these libraries diminished. As such, much of the Taglibs codebase moved into maintenance mode.

like image 962
Justin Wrobel Avatar asked Jun 20 '11 22:06

Justin Wrobel


1 Answers

You can use the JSTL substring function:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

${fn:substring(myVariable, 0, 5)}
like image 55
Etienne Neveu Avatar answered Sep 21 '22 18:09

Etienne Neveu