简体   繁体   English

Http Status 404错误处理spring mvc

[英]Http Status 404 error handling spring mvc

How can I implement custom http error handling in spring mvc. 如何在spring mvc中实现自定义http错误处理。

For example: I have a url http://localhost:8080/demo/canvas 例如:我有一个网址http:// localhost:8080 / demo / canvas

It display my canvas page but if the user missed the url and typed http://localhost:8080/demo/canva 它显示我的画布页面,但如果用户错过了网址并输入了http:// localhost:8080 / demo / canva

It shows me Tomcat Rendered HTTP Status 404. I want it to be custom jsp page. 它向我展示了Tomcat呈现的HTTP状态404.我希望它是自定义的jsp页面。

In your web.xml you can provide a custom error page mapping based upon the error code: 在您的web.xml您可以根据错误代码提供自定义错误页面映射:

<error-page>
    <error-code>404</error-code>
    <location>/PageNotFoundError.jsp</location>
</error-page>

This jsp file will be present parallel to WEB-INF folder. 此jsp文件将与WEB-INF文件夹并行存在。

Working in my application,, try this 在我的应用程序中工作,试试这个

    </web-app>  
      <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/resources/jsp/404.jsp</location>
      </error-page>
    </web-app>

Note: Make sure u restart server each time wen u make changes in web.xml 注意:确保每次在web.xml中进行更改时重新启动服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM