URL Pattern Restricting in SPRING MVC
Asked Answered
E

2

9

My Spring Web MVC application has the following handler mapping in the Controller.

@RequestMapping(method = RequestMethod.GET, value = "/something")

When request is sent to

http://www.someURL.com/something

, it works fine and maps to correct controller but,

http://www.someURL.com/something.bak or http://www.someURL.com/something.abc or http://www.someURL.com/something.abc.deff.xyz also works!!

I want to restrict this to just http://www.someURL.com/something and not to others.

web.xml defines the mappings as :-

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

Please suggest.

Exertion answered 4/6, 2012 at 14:41 Comment(0)
T
4

You can use the useDefaultSuffixPattern property.

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="useDefaultSuffixPattern" value="false" />
</bean>
Tintometer answered 4/6, 2012 at 15:58 Comment(1)
Hey This works thanks.But need to remove <mvc:annotation-driven> from servelt mapping xml.Exertion
C
1

In addition to above, refer to documentation below: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.html

Method: setUseDefaultSuffixPattern()

Also go through similar queries asked below: How to change Spring MVC's behavior in handling url 'dot' character

Closefitting answered 4/6, 2012 at 17:19 Comment(1)
Looks like MVC Annotation Driven and bean method does not work together. we have to remove MVC Annotation Driven for other to work.Closefitting

© 2022 - 2024 — McMap. All rights reserved.