按道理這應該非常簡單,百度一堆,但是竟然每一個方法都沒用,而且大部分文字都是爬蟲的。
我的方法如下
1、web.xml下加
。。。。。
<error-page>
<error-code>404</error-code>
<location>/html/404.html</location>
</error-page>
</web-app>
2、WEB-INF/下的spring mvc的xml配置文件
<mvc:resources location="/html/" mapping="/html/**"/>
3、webapp或者webContent下,加入html,自定義404頁
4、原理
訪問一個不存在的url,會出現404錯誤,然後
(1)程序查找web.xml文件裏404配置,對應路徑是 /html/404.html
(2)”/html/404.html“在applicationContent.xml裏找到<mvc:resources的配置,發現url符合mapping。
(3)把第二步的location取出來,即/html/,也就是webContent/html/404.html