sidlejinks
sidlejinks

Reputation: 709

Spring MVC eliminate *.html pattern

I use Spring MVC 3.1 with following front controller configuration:

<servlet>
        <servlet-name>paymentSystemServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/servlet-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>paymentSystemServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

Because I have pattern like "*.html" I have to do next thing. I need an html extension in all my url's to controller (e.g. 'a href=/admin.html' intercepts controller with request mapping '/admin'). Can I configure some url-pattern in order to avoid html extensions in my url? Thank you.

Upvotes: 1

Views: 977

Answers (1)

slashdot
slashdot

Reputation: 786

By mapping DispatcherServlet to /, you can use it as a default servlet and it’ll be responsible for handling all requests including html, htm etc.

<servlet-mapping>
        <servlet-name>spitter</servlet-name>
        <url-pattern>/</url-pattern>
</servlet-mapping>

Or you can use the Spring MVC 3.x default servlet handler to do the job. Just add that following to the Spring XML config.

<mvc:default-servlet-handler/>

Upvotes: 2

Related Questions