在struts中的国际化如何处理? JSP页面上直接<bean:message key="login.title" /> 解决国际化显示的问题
ActionErrors errors = new ActionErrors() ;
if (this.username != null && this.username.length() < 4 ) {
errors.add("username", new ActionMessage("username.tooshort",new Object[]{username,"x","xxx"})) ; ;
}
在ActionErrors中的错误消息在JSP页面上用
<html:errors property="username" />
显示
ActionMessages中的消息如何在JSP页面上显示?
ActionMessages messages = new ActionMessages() ;
String forward = "fail" ;
if ("admin".equalsIgnoreCase(uaf.getUsername()) && "admin".equalsIgnoreCase(uaf.getPassword())) {
messages.add("success", new ActionMessage("login.success",uaf.getUsername())) ;
forward = "success" ;
this.addMessages(request, messages) ;
}else{
messages.add("fail", new ActionMessage("login.fail",uaf.getUsername())) ;
this.addMessages(request, messages) ;
}
ActionMessages中的信息在JSP页面上用下面的标签来显示:
<html:messages id="msg" message="true" property="success" >
<bean:write name="msg" />
</html:messages>
自定义的异常在struts中如何处理?
自定义一个异常类,在处理业务逻辑中一直往上抛,在struts中统一管理
struts.cfg.xml中配置如下
<global-exceptions>
<exception type="com.cs.util.SystemException" key="system.error" path="/common/exception.jsp" />
</global-exceptions>
所有的forword,只要没有跳转,就统一跳到这个全局异常页面
在exception.jsp页面中用<html:errors />即可得到所有的异常信息
注意:在资源文件中配置:system.error {0} ,对应上面的key值(内部处理:有错误就把错误放到{0}中去)
分享到:
相关推荐
Struts2异常处理机制
项目中出现的异常通常要用一个友好的异常页面来显示,通过对struts2.xml的配置能拦截全局异常,只要出现异常就会转向异常页面。
NULL 博文链接:https://wlh269.iteye.com/blog/321746
配合博文:http://blog.csdn.net/u011638419/article/details/41343683
NULL 博文链接:https://yuxisanren.iteye.com/blog/1707508
NULL 博文链接:https://wjt276.iteye.com/blog/690323
struts2的异常处理,解决异步请求时,异常以json格式发送到客户端。以及dao单元测试的配置。
struts常见异常及处理
从网上搜索的一段关于struts1.x自定义异常处理的方法。
本文档主要介绍了struts2的异常处理机制,希望对你有所帮助。
Struts2的异常处理实例 博文链接:https://zmx.iteye.com/blog/463996
Struts2 异常处理的四种获取属性方法,大家可以借鉴学习
struts2 单文件,多文件上传及异常处理
struts2异常处理实例
Struts+Hibernate+Spring(加入了struts完整的自动异常处理和国际化)源码
通过定义继承RuntimeException的异常类及继承ExceptionHandler的异常处理类,手动从dao层捕获异常。非常实用!
NULL 博文链接:https://xace.iteye.com/blog/416561
Struts简介 什么是Struts Struts基本运作流程 ActionMapping类 Action类 ActionForm类 ActionError与ActionMessage 协同开发 模块化程序 Struts异常处理 Struts国际化支持 PlugIn接口 等等
Struts2处理类型转换错误,全局处理,如处理时间转换错误