我看过这篇文章:Spring MVC; avoiding file extension in url?
这不管用..。当我使用
<servlet-mapping>
<servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
我得到了警告
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'
我的默认设置是使用*.htm
和URL http://localhost:8080/CMT/content/edit.htm
,但我希望使用http://localhost:8080/CMT/content/edit
我还需要能够加载资源,比如位于CMT/js
、CMT/css
和CMT/lib
中的js/css文件
发布于 2012-03-15 04:03:53
您是否正确地映射了您的URL,以便同时捕获edit.htm
和edit
?尝试(假设CMT是您的contextPath):
@RequestMapping(value = "/content/edit*")
要让资源正常工作,您需要在spring配置中指定<mvc:resources .../>
。请参阅Spring doco here。
编辑: Spring提供了一个DefaultAnnotationHandlerMapping
bean,它通常可以捕获可能的扩展,如.html、.xml等。我正在开发的应用程序通过以下方式关闭了这一功能:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="useDefaultSuffixPattern" value="false"/>
</bean>
因此,您通常不必担心扩展。
发布于 2012-03-14 23:04:28
在路径中包括目录组件。(您可能不希望映射匹配所有内容,包括内部请求。)
https://stackoverflow.com/questions/9703382
复制相似问题