說的配置404,你們都會想到去web.xml裏面配置html
<error-page> <error-code>404</error-code> <location>/404.html</location> </error-page>
但是若是我有業務需求,當發生404,我要記錄相關信息呢?或者說404的展現頁面我也有須要動態獲取的資源呢?那麼靜態頁面就力不從心了。web
那麼先寫一個處理404的方法spring
//404 @RequestMapping(value="/404") public String notFound(){ //do something return "404"; }
用過springmvc的我就不解釋上面代碼了apache
接下來配置web.xml(說實話我傻逼似的一直認爲這裏只能配置靜態資源,漲姿式了)mvc
<error-page> <error-code>404</error-code> <!-- 這裏能夠爲servlet,不必定非要靜態資源 --> <location>/404</location> </error-page>
若是你項目中沒用到shiro的就能夠到此爲止了app
shiro項目會報錯:url
org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code
經網上查看便知spa
在web.xml的配置文件裏面,應該這樣配置shirocode
<!-- Shiro Filter is defined in the spring application context: --> <filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping>
重點是xml
<dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher>
這幾行代碼。
到此運行工程,404完美了