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
\n does not represent the newline character in an EL expression.
The solution which sets a pageContext attribute to the newline character and then uses it with JSTL's fn:replace function does work.
However, I prefer to use the Jakarta String Tab Library to solve this problem:
<%@ taglib prefix="str" uri="http://jakarta.apache.org/taglibs/string-1.1" %>
...
Text containing newlines
...
You can use whatever you want for the newlineToken; "~n" is unlikely to show up in the text I'm doing the replacement on, so it was a reasonable choice for me.