2016-09-30 164 views
2

我有以下的web.xml:的web.xml错误页404错误路径

<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> 

当我去localhost:port/myapplication/someincorrecturl它正确地重定向我index.html文件。但是,当我去localhost:port/myapplication/someincorrecturl1/someincorrecturl2该应用程序给我一个404错误。如何解决具有多个路径的任何不正确的URL的问题?

回答

0

如果您在Tomcat上部署了应用程序,并且您只是输入localhost或localhost:port,它将不会重定向到您的应用程序。

您可以通过输入localhost:port/YourProjectName来进行访问。它是你的项目的根,如果你想访问任何其他资源,你可以通过localhost访问它:port/YourProjectName/OtherResource。如果OtherResource不存在,并且你已经用index.jsp映射了404错误,它将把它重定向到index.jsp。

您错误地提供了根和子路径。

+0

正确我忘记把我的问题中的应用程序。我刚刚编辑它。 – user1383093

+0

将它添加到web.xml Project Name中,你现在面临同样的问题了吗? – sajid

+0

是的,错误是一样的 – user1383093