How can I replace newline characters using JSP and JSTL?

Here is a solution I found. It doesn’t seem very elegant, though:

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<% pageContext.setAttribute("newLineChar", "\n"); %>

${fn:replace(item.comments, newLineChar, "; ")}

Leave a Comment