Jackson ObjectMapper 的替代方案
我正在寻找一个与 Jackson ObjectMapper
一起使用或代替 Jackson ObjectMapper
的标签库。我正在升级我们的网站,并且我们的 JSP 文件中不允许内联代码块。因此我需要找到一些可以解决我的问题的标签库。
<jsp:useBean id="mapper" class="org.codehaus.jackson.map.ObjectMapper" />
<%=mapper.writeValueAsString(pageContext.getAttribute("result"))%>
但我无法将其转换为这样的内容:
<c:out value="${mapper.writeValueAsString(pageContext.getAttribute('result'))}"></c:out>
这会引发异常:
未指定默认命名空间时,函数 writeValueAsString 必须使用前缀
谢谢。
I am looking for a taglib to be used with or instead of Jackson ObjectMapper
. I am working on upgrading our website, and we do not allow inline code blocks in our JSP files. So therefor I need to find some tag library that can solve my problems.
<jsp:useBean id="mapper" class="org.codehaus.jackson.map.ObjectMapper" />
<%=mapper.writeValueAsString(pageContext.getAttribute("result"))%>
But I can not convert this to something like this:
<c:out value="${mapper.writeValueAsString(pageContext.getAttribute('result'))}"></c:out>
This throws exception:
The function writeValueAsString must be used with a prefix when a default namespace is not specified
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义自定义 JSTL 函数:
:。
然后您可以将其与
f:getJSON(..)
一起使用,但一般来说,在 JSP 中执行此操作可能并不正确 - 在控制器/servlet 中预先计算它,并将其添加为模型属性。
Define a custom JSTL function:
.
Then you can use it with
f:getJSON(..)
But generally, it might not be right to do this in the JSP - precompute it in the controller/servlet, and add it as model attribute.
我通过在 WEB-INF 文件夹中的 .tag 文件中实现该功能解决了这个问题,在该文件夹中我们允许内联编码。不完全是最好的解决方案,但它确实有效。
I solved this, by implementing the functionality in a .tag file in the WEB-INF folder, where we allow inline coding. Not exactly the best solution, but it works.