2

I've looked at this post: Spring MVC; avoiding file extension in url?

This isn't working.... when I use

<servlet-mapping>
    <servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

I get the warning

WARNING: No mapping found for HTTP request with URI [/CMT/WEB-INF/jsp/content/edit.jsp] in DispatcherServlet with name 'Spring-MVC-Dispatcher-Servlet'
WARNING: No mapping found for HTTP request with URI [/CMT/WEB-INF/jsp/content/edit.jsp] in DispatcherServlet with name 'Spring-MVC-Dispatcher-Servlet'

My default settings are using *.htm and the URL http://localhost:8080/CMT/content/edit.htm, but I'd like to be using http://localhost:8080/CMT/content/edit

I also still need to be able to load resources like js/css files located in CMT/js, CMT/css and CMT/lib

Community
  • 1
  • 1
Ben
  • 60,438
  • 111
  • 314
  • 488
  • 1
    Your servlet mapping is OK. But have you defined a Spring MVC controller that cares about URLs like `/CMT/*`? – AlexR Mar 14 '12 at 14:03
  • possible duplicate of [No mapping found for HTTP request with URI \[/WEB-INF/pages/apiForm.jsp\]](http://stackoverflow.com/questions/1266303/no-mapping-found-for-http-request-with-uri-web-inf-pages-apiform-jsp) – krock Mar 14 '12 at 14:05
  • @krock - It's not, In the above example I'm using the fix suggested in that question – Ben Mar 14 '12 at 14:09
  • @AlexR - No, I suppose not... I don't want just any URL to work though. If there's not a mapping for it I want it to fail. I just don't want a file extension. – Ben Mar 14 '12 at 14:10
  • Show us your controller code - specifically your `@RequestMapping` annotations. Have you included * at the end of them: `@RequestMapping(value = "/content/edit*")` – nickdos Mar 15 '12 at 04:00

2 Answers2

0

Include a directory component in the path. (You probably do not want the mapping to match everything including internal requests.)

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75
0

Are you mapping you URLs correctly so as to catch both edit.htm and edit? Try (assuming CMT is your contextPath):

@RequestMapping(value = "/content/edit*")

To get resources working, you need to specifiy <mvc:resources .../> in your spring config. See the Spring doco here.

EDIT: Spring provides a DefaultAnnotationHandlerMapping bean which usually catches possible extensions like .html, .xml, etc. The app I'm working on has this turned off via:

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="useDefaultSuffixPattern" value="false"/>
</bean>

So you should not have to worry about the extension normally.

nickdos
  • 8,348
  • 5
  • 30
  • 47
  • Is there a way to do this without using a wildcard... maybe I put together `/content/editUsers/` or something... I want to be sure it doesn't match `/content/edit/` – Ben Mar 15 '12 at 19:07
  • Yes, you can use a `String[]` in the value part to specify it can match two or more URls: `@RequestMapping(value = {"/content/edit","/content/edit.htm"})` – nickdos Mar 15 '12 at 23:42
  • if I do that though, it still won't match the `*.htm` in my `web.xml`. I've already tried using `/*` there and it doesn't match. – Ben Mar 16 '12 at 11:21
  • There was no mention of `*.htm` in web.xml in your question... Spring recommends using `/*` (as did the other Q you referenced). Otherwise you're static resources won't work (*.js, *.css) without separate mappings. – nickdos Mar 16 '12 at 21:50