简体   繁体   中英

web.xml error-page 404 error path

I've the following web.xml:

<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/mvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
</error-page>

When I go to localhost:port/myapplication/someincorrecturl it properly redirects me to index.html file. But when I go to localhost:port/myapplication/someincorrecturl1/someincorrecturl2 the application gives me a 404 error. How can I solve the problem for any incorrect URL with more than one path?

If you have deployed your application on Tomcat and you are just typing localhost or localhost:port it won't redirect to your application.

You can access by typing localhost:port/YourProjectName. It is root of your project and if you want to access any other resource you can access it by localhost:port/YourProjectName/OtherResource. If OtherResource is not present and you have mapped 404 error with index.jsp it will redirect it to index.jsp.

You are giving both root and subpath wrongly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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