我是 struts 新手,如何在 struts2 jsp 页面中装饰动作消息和动作错误?
<s:actionmessage/>
<s:actionerror/>
您可以使用 css 样式以及 jquery 主题属性来装饰您的操作错误和操作消息。
<div class="error"><s:actionerror theme="jquery"/></div>
<div class="message"><s:actionmessage theme="jquery"/></div>
.message li
{
font-size: 14px;
color: #000066;
text-align: center;
list-style: none;
font-family: Trebuchet MS,sans-serif,inherit,Arial,monospace;
}
.error li
{
font-size: 14px;
color: #990000;
text-align: center;
list-style: none;
padding-right: 50px;
}
嗨,如果您希望您的操作消息和错误消息来装饰使用此代码,我在这里发布您的问题的解决方案
<div id="sucessMsg"><s:actionerror /></div>
sucessMsg is the class that is using by struts2 internally so override this so kindly put the below code inside the css
#sucessMsg {
text-align: center;
font-weight: bolder;
color: #6A2A91;
list-style: none;
margin: auto;
}
#errorMsg {
text-align: center;
font-weight: bolder;
color: red;
list-style: none;
width: 350px;
margin: auto;
}
You should view the HTML source after it is rendered to see the CSS classes and HTML structure that Struts uses to render the message. You can also look in the template files.
By Default struts renders each action message as follows:
<ul>
<li><span class="actionMessage">${message}</span></li>
</ul>
Every message will have a <li><span class="actionMessage">${message}</span></li>
.
You can create CSS for actionMessage or change the template file to render these however you want.
The template files for these are located in:
/template/simple/actionerror.ftl
/template/simple/actionmessage.ftl
Field Error might be useful to you as well:
/template/simple/fielderror.ftl
note: if you are using the xhtml theme those files may be located in that folder under template