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
相关文章
评论:
验证码:
匿名评论:

最新文章

文章排行