0

我有一个属性文件(资源包)。我试图通过从属性文件加载它们来显示其中一个 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>

上面使用struts 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)
  • 不包含用户 ID
  • 不包含长度超过 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 相同的错误。

4

1 回答 1

0

<s:actionerror/>and标签将把你的and <s:actionmessage/>封装在.actionerrorsactionmessages<ul><li><span>yourmessage</span></li></ul>

这将使您的消息以一个圆点开头(因为它在一个 内<li>),而另一个嵌套<li>在圆形轮廓中(由 HTML 为 second-level 定义<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>

您可以执行循环 for actionMessagesactionErrors并最终fieldErrors将它们放在一个messages.jsp片段中,这样您就可以在每个页面中使用它(无需每次都重写它),例如:

<s:include value="/WEB-INF/content/fragments/messages.jsp" />
于 2015-01-09T13:48:03.593 回答