springmvc 添加传参自定义异常
springmvc默认url参数传递的异常是不显示的,被spring给吃掉,
当自己传参到controller层时不知道遇到什么错误,我在form表单提交的时候时间类型的参数写错
直接报404错误而不显示参数错误信息。
下面介绍一下springmvc自定义参数异常:
1.添加自定义异常类该类继承DefaultHandlerExceptionResolver:
package org.test.common; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; public class CustomHandlerExceptionResolver extends DefaultHandlerExceptionResolver { private static final Log LOG = LogFactory.getLog(CustomHandlerExceptionResolver.class); @Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { LOG.error(request.getRequestURI(), ex); return super.doResolveException(request, response, handler, ex); } }
2.applicationContext.xml文件添加bean,order设置为优先级,值越小优先级越高:
<bean id="customHandlerExceptionResolver" class="org.test.common.CustomHandlerExceptionResolver" > <property name="order" value="1"></property> </bean>
来源://作者:admin/更新时间:2013-12-15
顶
踩
相关文章:
- springmvc 表单提交时间字段_springMVC form提交404
- 解决org.springframework.beans.factory.BeanCreation
- springmvc form表单提交后台对象获取不到值(解决)
- springmvc form提交使用@ModelAttribute后台取得乱码
- (解决) springmvc jsp界面显示乱码 spring+mybatis+my
- spring jar framework 下载地址(解决)
- Field or property 'jobParameters' cannot be found
- MINA2官方教程翻译(10)与Spring整合
- spring Bean property 'backupService' is not writab
- spring +mybatis 出现The content of elements must c