KasparTr
KasparTr

Reputation: 2458

Spring MVC Servlet Mapping using dispatcher

I am using web.xml to divert any .htm to dispatcher.

web.xml:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

In my dispatcher I say:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="index.htm">indexController</prop>
            <prop key="books.htm">bookServlet</prop>
        </props>
    </property>
</bean>

Now all works but I need a method inside BookServlet to work when the url is .../books.htm/doSomething I use RequestMapping inside the servlet like so:

@RequestMapping(value = "book.htm/doSomething", method = RequestMethod.GET)

But when I add /doSomething I lose the servlet because is it not mapped to the servlet in the dispatcher anymore. I am confused as to how do I use /* approach in dispather because it sure is not working line in the web.xml.

Upvotes: 0

Views: 199

Answers (1)

Rokin Maharjan
Rokin Maharjan

Reputation: 689

Try replacing *.htm in your in the with /

i.e.

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

Upvotes: 0

Related Questions