Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the exception handling of Spring3.0.5 MVC

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about Spring 3.0.5 MVC exception handling is how, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

SimpleMappingExceptionResolver

Simple, clear, sufficient, mapping between exception type and view, any custom exception type can be mapped here and error page, granular enough

springmvc.xml

XML code

redirect:/error.jsp? flag=BaseServiceException prop> redirect:/error.jsp? flag=RuntimeException prop> props> property> bean>

Spring 3 adds an exception handler annotation to the Control class.

Java code

@RequestMapping("exception") public void throwException() { throw new RuntimeException("This is the runtime exception"); } @ExceptionHandler(Exception.class) public @ResponseBody String handleException(Exception ex) { return ex.getMessage(); }

@ExceptionHandle can also be abstracted into BaseControl, but @ExceptionHandle will not work if SimpleMappingExceptionResolver is used

HandlerExceptionResolver

Custom exception implementation

Java code

public class WebExceptionResolver implements HandlerExceptionResolver { public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception e) { HttpSession session = request.getSession(); session.getId(); //exception handling return null; } }

springmvc.xml

XML code

The above is how Spring 3.0.5 MVC exception handling is, Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report