Welcome file in web.xml with spring not working?

I installed my spring -mvc servlet to match * .page requests. I set the welcome list of the file in web.xml as index.page

This works when I go to the root of my web server:

http://me.com redirects to http://me.com/index.page correctly.

However, it does not redirect when I use subdirectoris:

http://me.com/dashboard is not redirected to http://me.com/dashboard/index.page

Is there any way to make this mapping work?

My web.xml (extract) file:

<welcome-file-list>
    <welcome-file>index.page</welcome-file>
</welcome-file-list>

<servlet-mapping>
    <servlet-name>spring-mvc</servlet-name>
    <url-pattern>*.page</url-pattern>
</servlet-mapping>

My webdefault.xml (off the marina):

    <init-param>
        <param-name>dirAllowed</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>welcomeServlets</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>redirectWelcome</param-name>
        <param-value>false</param-value>
    </init-param>
+5
source share
4 answers

, , .

Spring MVC URL-, @RequestMapping

+3

<welcome-file> , , (, root /, , /foo/). , servletcontainer , , HTTP 404.

index.page . index.jsp . index.page - URL. , servletcontainer index.page , , 404.

, servletcontainer, index.page index.jsp . . , index.page, , , , index.jsp as. .

+12

, .

  <servlet-mapping>
     <servlet-name>spring-mvc</servlet-name>
     <url-pattern>index.html</url-pattern>
  </servlet-mapping>

java , WebMvcConfigurerAdapter

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("/index");
}

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

index.html, , , :

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/index.html").addResourceLocations("/WEB-INF/views/index.html");
}

, addResourceLocations , .

+2

, , , -, , ,

Apache HTTP Server , DirectoryIndex : DirectoryIndex index.page

-, - web.xml ( tomcat)? - , .

0

All Articles