当一个请求提交到服务器后,服务器进行处理,若输入错误或者进行提示,需要返回原输入页面将错误信息呈现给用户....
具体实现:
ApplicationResources.properties
====================================
# Resources for parameter 'com.lhcard.struts.ApplicationResources'
# Project LhCard
geren.userlogin.error.authencode=<font color="red">\u9a8c\u8bc1\u7801\u9519\u8bef</font>
geren.userlogin.error.password=<font color="red">\u5bc6\u7801\u9519\u8bef</font>
geren.userlogin.error.name=<font color="red">\u6ca1\u6709\u6b64\u7528\u6237</font>
geren.regisgter.error.name=<font color="red">\u6b64\u7528\u6237\u540d\u5df2\u88ab\u4eba\u6ce8\u518c\uff0c\u8bf7\u66f4\u6362\u4e00\u4e2a</font>
action:
=====================
ActionMessages messages = new ActionMessages();
messages.add("exist_name", new ActionMessage(
"geren.regisgter.error.name"));
request.setAttribute("msg", messages);
return mapping.findForward("reg");
jsp页面:
===========================
<html:messages id="c" name="msg" property="exist_name">
${c } </html:messages>
此标签中的name属性指定request作用域中的key,property指定错误消息的key
具体实现:
ApplicationResources.properties
====================================
# Resources for parameter 'com.lhcard.struts.ApplicationResources'
# Project LhCard
geren.userlogin.error.authencode=<font color="red">\u9a8c\u8bc1\u7801\u9519\u8bef</font>
geren.userlogin.error.password=<font color="red">\u5bc6\u7801\u9519\u8bef</font>
geren.userlogin.error.name=<font color="red">\u6ca1\u6709\u6b64\u7528\u6237</font>
geren.regisgter.error.name=<font color="red">\u6b64\u7528\u6237\u540d\u5df2\u88ab\u4eba\u6ce8\u518c\uff0c\u8bf7\u66f4\u6362\u4e00\u4e2a</font>
action:
=====================
ActionMessages messages = new ActionMessages();
messages.add("exist_name", new ActionMessage(
"geren.regisgter.error.name"));
request.setAttribute("msg", messages);
return mapping.findForward("reg");
jsp页面:
===========================
<html:messages id="c" name="msg" property="exist_name">
${c } </html:messages>
此标签中的name属性指定request作用域中的key,property指定错误消息的key