Struts2 属性标签escapeHtml 不起作用我错过了什么吗? [英] Struts2 property tag escapeHtml is not working am I missing something?

查看:81
本文介绍了Struts2 属性标签escapeHtml 不起作用我错过了什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码无法正常工作.我想从 bean 中获取以下 Java 字符串

The following code is not working correctly. I would like to take the following Java String from the bean

String statusMsg = "Hello World! <br/><br/><h3>Test</h3>"

并输出没有转义的 HTML 标签.

And output it with the HTML tags not escaped.

<s:property escapeHtml="false" value="bean.statusMsg"

这个属性 Tag 和 String 的结果,是 HTML 标签还在被转义,我是不是遗漏了什么?

The result of this property Tag and String, is that the HTML tags are still being escaped, am I missing something?

我的目标是最终构建一个状态数据表并将其输出到页面上这是使用属性标记的错误方式吗?预先感谢您的帮助.

My goal is to eventually build a table of status data and output it on the page is this the wrong way to use the property tag? Thank you in advance for your help.

当前输出如下

Hello World! <br/><br/><h3>Test</h3>

我希望它使用标签并添加几行新行并使 Test 成为标题.这是目前所有的测试代码,只是想让它工作.

I would like it to use the tags and add a couple of new lines and make Test a header. This is all test code right now, just trying to get it to work.

推荐答案

你能试试吗

<s:property escape="false" value="bean.statusMsg"/>

据我所知,如果您使用通常的 Struts 属性元素来显示数据,它将转义 html 代码.因此,您必须关闭转义:

As per my knowledge If you use the usual Struts property element for displaying data, it will escape html code. Hence, you have to turn off escaping:

这里有更多细节

Struts2 属性标签

更新

我尝试了该属性,并且无论哪种方式都可以完美运行.我尝试了两种方式在我的 Action 类中创建一个属性,并在该 bean 中创建了一个 bean 和相同的属性

I tried the property and its working perfectly either way. i tried it in two way create a property in my Action class and also created a bean and the same property inside that bean

我使用了escapeHtml,它在两种情况下都能完美运行.此外,如果您想显示数据并以格式化的方式显示它,我怀疑这是正确的方法.我的建议是最好在你的 JSP 中使用一些 CSS/HTML 来格式化输出,而不是从属性标签中获取帮助

than i used the escapeHtml and it worked perfectly in both cases. Additionally if you want to display data and show it in formatted way i am doubtful this is the right way to do this. My suggestion is better use some CSS/HTML in your JSP to format the output rather than taking help from the property tag

要调查问题,请提供您的操作和 JSP 类的代码.

To look in to the issue provide the code of your action and JSP classes.

这篇关于Struts2 属性标签escapeHtml 不起作用我错过了什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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