2012-01-28 81 views

回答

16

是的,有一種方法,你應該抓住MissingServletRequestParameterException

你能做到在幾個方面:

1)

@ExceptionHandler(MissingServletRequestParameterException.class) 
     public String handleMyException(Exception exception) { 
     return "yourErrorViewName"; 
       } 

2)

<error-page> 
    <exception-type>org.springframework.web.bind.MissingServletRequestParameterException</exception-type> 
    <location>/WEB-INF/pages/myError.jsp</location> 
    </error-page> 

希望它幫助。

4

我如何解決我的問題:

@ResponseBody 
@ExceptionHandler(MissingServletRequestParameterException.class) 
public Object missingParamterHandler(Exception exception) { 
    // exception handle while specified arguments are not available requested service only. it handle when request is as api json service  
    return new HashMap() {{ put("result", "failed"); put("type", "required_parameter_missing");}}; 
}