0

As Spring MVC 3 handles requests through annotations. @RequestMapping(value = "/welcome") etc

My application URL is https://localhost:9452/clientapp/welcome.htm

This URL opens up welcome page.

My web.xml is:

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

How to handle/catch this request with no welcome.htm.

https://localhost:9452/clientapp/

I tried using this but in vain

@RequestMapping(value = { "/*.htm", "/**/*.htm", "/*", "/**/*" })
Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190

1 Answers1

1

One of the reasons is that you set your spring dispatcher servlet to handle only ".htm" and ".do" in your servlet mapping.

Spring MVC works on top of servlet api and to make to spring controller serve requests to some url those requests should be served by dispatcher servlet in the first place.

Try to use:

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

in your web.xml

Eugene Loy
  • 12,224
  • 8
  • 53
  • 79
  • This stops loading my resources like images and css files. – Muhammad Imran Tariq May 08 '13 at 07:09
  • Well, thats probably because you not fully configured your dispatcher servlet context. Since dispatcher servlet will handle all requests you'll need to tell it where to look for the resources. See Ralph's answer here: http://stackoverflow.com/questions/8195213/spring-3-mvc-resources-and-tag-mvcresources , for example of how to do this. – Eugene Loy May 08 '13 at 08:47
  • I am not really sure whether dispatcher servlet will allow loading resources from WEB-INF, so, just to test concept, I'd recomment you to do the following: (1) verify that your image is in "{appname.war}/images/imagename.png" , (2) add "" to your dispatcher servlet context, (3) run your war and try to fetch it with url like http://{host}/{appname}/resources/imagename.png . If this will work out - you should have a starting point to improve your config the way you want. – Eugene Loy May 08 '13 at 10:25
  • I did this but get error. 'No mapping found for HTTP request with URI [/clientapp/login.htm] in DispatcherServlet with name 'spring'' – Muhammad Imran Tariq May 08 '13 at 10:46
  • My resources are under WebContent folder in hierarchy with WEB-INF folder. – Muhammad Imran Tariq May 08 '13 at 10:48
  • Also, you might want to check "". As far as I recall this is some sort of fallback mean related to among other to resources, but I am not really remember all the details at the moment, so it is better to check docs... – Eugene Loy May 08 '13 at 11:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29593/discussion-between-imran-tariq-and-leo) – Muhammad Imran Tariq May 08 '13 at 11:11