I have a list of bean objects passed into my JSP page, and one of them is a comment field. This field may contain newlines, and I want to replace them with semicolons using
This solution is more elegant than your own solution which is setting the pagecontext attribute directly. You should use the <c:set>
tag for this:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="newLine" value="\n"/>
${fn:replace(data, newLine, "; ")}
BTW: ${fn:replace(data, "\n", ";")}
does NOT work.
In the value while setting the var, press ENTER between the double quotes.
${fn:replace(data, newLineChar, ";")}