How to show user-friendly error page in browser when runtime exception is thrown by servlet?

后端 未结 3 1955
清歌不尽
清歌不尽 2020-11-29 01:15

I\'m developing web-application with JSF. I tested it as I was able to but from time to time runtime exceptions are thrown.

So, how to redirect user to special error

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 01:36

        If you use java config in spring, you can follow,
    
       @Configuration
       public class ExcpConfig {
    
        @Bean(name = "simpleMappingExceptionResolver")
        public SimpleMappingExceptionResolver simpleMappingExceptionResolver() {
            SimpleMappingExceptionResolver resolver= new SimpleMappingExceptionResolver();
    
            Properties mappings = new Properties();
            resolver.setExceptionMappings(mappings); // None by default
            resolver.setExceptionAttribute("ErrorOccurred"); // Default is "exception"
            resolver.setDefaultErrorView("500"); // 500.jsp
            return r;
        }
    
    }
    

提交回复
热议问题