我有一个属性文件(资源包)。我试图通过从属性文件加载它们来显示其中一个 jsp 中的错误。我的属性文件中有一个条目,如下所示。
errors.password.rules=<font color="red">The password you have entered does not meet password strength requirements. Please select a new password that conforms to the following standards:<UL><LI>Minimum length of 8 characters</LI> <LI>Maximum length of 18 characters</LI><LI>At least one upper-case character</LI> <LI>At least one lower-case character</LI><LI>At least one non-alphabetic character</LI> <LI>Does not contain 3 or more consecutive repeating characters (e.g. AAA)</LI> <LI>Does not contain the User ID</LI><LI>Does not contain common dictionary words more than 4 characters long</LI><LI>New Password should not be the same as previous password</LI></UL></font>
使用支柱 1 加载时,上述内容如下所示
The password you have entered does not meet password strength requirements. Please select a new password that conforms to the following standards:
- 最小长度为 8 个字符
- 最大长度为 18 个字符
- 至少一个大写字符
- 至少一个小写字符
- 至少一个非字母字符
- 不包含 3 个或更多连续重复字符(例如 AAA)
- 不包含用户标识
- 不包含长度超过 4 个字符的常用字典单词
- 新密码不应与以前的密码相同
加载 Struts 2 时相同,请参阅附件以获取输出
• The password you have entered does not meet password strength requirements. Please select a new password that conforms to the following standards: o Minimum length of 8 characters o Maximum length of 18 characters o At least one upper-case character o At least one lower-case character o At least one non-alphabetic character o Does not contain 3 or more consecutive repeating characters (e.g. AAA) o Does not contain the User ID o Does not contain common dictionary words more than 4 characters long o New Password should not be the same as previous password
上面显示的是带圆圈的项目符号,每个项目符号都在下一行中。子弹即将成为第一行
请建议我必须对我的属性文件进行哪些更改才能加载与 struts 1.x 相同的错误。
<s:actionerror/>
和 <s:actionmessage/>
标签将封装您的actionerrors
和actionmessages
<ul><li><span>yourmessage</span></li></ul>
中。
这将使您的消息以圆点开头(因为它位于<li>
内),另一个嵌套<li>
带有圆圈轮廓(由 HTML 定义的二级<li>
)。
这:
<s:actionmessage />
将生成:
<ul class="actionMessage"><li><span>
<font color="red">The password you have entered does not
meet password strength requirements. Please select a new password that conforms
to the following standards:<UL><LI>Minimum length of 8 characters</LI>
<LI>Maximum length of 18 characters</LI><LI>At least one upper-case character</LI>
<LI>At least one lower-case character</LI><LI>At least one non-alphabetic character</LI>
<LI>Does not contain 3 or more consecutive repeating characters (e.g. AAA)</LI>
<LI>Does not contain the User ID</LI><LI>Does not contain common dictionary words
more than 4 characters long</LI><LI>New Password should not be the same as
previous password</LI></UL></font>
</span></li></ul>
要生成你想要的输出,你可以编写自己的 .ftl,或者更容易避免使用 <s:actionerror/>
/<s:actionmessage>
标签,自己做循环:
<s:if test="actionMessages!=null && actionMessages.size > 0">
<div class="actionmessage">
<s:iterator value="actionMessages" >
<span>
<s:property escapeHtml = "false" />
</span>
<br/>
</s:iterator>
</div>
</s:if>
结果:
<div class="actionmessage"><span>
<font color="red">The password you have entered does not
meet password strength requirements. Please select a new password that conforms
to the following standards:<UL><LI>Minimum length of 8 characters</LI>
<LI>Maximum length of 18 characters</LI><LI>At least one upper-case character</LI>
<LI>At least one lower-case character</LI><LI>At least one non-alphabetic character</LI>
<LI>Does not contain 3 or more consecutive repeating characters (e.g. AAA)</LI>
<LI>Does not contain the User ID</LI><LI>Does not contain common dictionary words
more than 4 characters long</LI><LI>New Password should not be the same as
previous password</LI></UL></font>
</span><br/></div>
您可以循环 actionMessages
、 actionErrors
并最终fieldErrors
并将它们放在一个messages.jsp
片段中,这样您就可以在每个页面中使用它(无需每次都重写它),如下所示:
<s:include value="/WEB-INF/content/fragments/messages.jsp" />