Spring MVC: preventing file extension in url

I looked at this post: Spring MVC; avoid file extension in url?

This does not work .... when I use

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

I get a 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 use *.htm and URL http://localhost:8080/CMT/content/edit.htm , but I would like to use http://localhost:8080/CMT/content/edit

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

+2
source share
2 answers

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

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

To work with resources, you need to specify <mvc:resources .../> in the spring configuration. See Spring doco here .

EDIT: spring provides a DefaultAnnotationHandlerMapping bean that usually catches possible extensions like .html, .xml, etc. The application I'm working on has disconnected through:

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

Therefore, you do not need to worry about the extension usually.

0
source

Include a directory component in the path. (You probably don't want the matching to match everything, including internal queries.)

0
source

Source: https://habr.com/ru/post/986293/


All Articles