如何使用 JSP 和 JSTL 替换换行符? [英] How can I replace newline characters using JSP and JSTL?

查看:32
本文介绍了如何使用 JSP 和 JSTL 替换换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个传递到我的 JSP 页面的 bean 对象列表,其中之一是注释字段.该字段可能包含换行符,我想使用 JSTL 将它们替换为分号,以便该字段可以在文本输入中显示.我找到了一种解决方案,但它不是很优雅.我会在下面发帖作为可能.

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 JSTL, so that the field can be displayed in a text input. I have found one solution, but it's not very elegant. I'll post below as a possibility.

推荐答案

这是我找到的解决方案.不过,它看起来并不优雅:

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", "
"); %>

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

这篇关于如何使用 JSP 和 JSTL 替换换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆