Home > Back-end >  For springmvc request path mismatch problem
For springmvc request path mismatch problem

Time:09-27

. The following is the web in XML configuration, when the path is configured to:/test/*, this is not matching the corresponding methods of annotation, but if change the path to the test/add, this change can access to the I added requestmapping annotations of the add method, what a great god can be solved excuse me? Thank you!

Spring - mvc

Org. Springframework. Web. Servlet. DispatcherServlet

ContextConfigLocation
/WEB - INF/spring MVC - servlet. Xml

1


Spring - mvc
& lt; Url - pattern>/test/* & lt;/url - pattern>

CodePudding user response:

In the web. The XML configuration when the DispatcherServlet will url - the pattern configuration into the following forms:
/rest/* & lt;/url - pattern>
1
Methods in the Controller of the above map path configuration into the following several ways:

1./rest/url/url2
The browser enter localhost: 8080/rest/url/url2
Is can't access the resources of
2./url/url2 in the browser to access localhost: 8080/rest/url/url2 can access to
Thinking:
Url - patter/xx/* this form in the map to the controller when * path before cancelling out, * matches only the last one,
Experiment 1:
Urlpattern configuration for the/rest/path/*
@ requetMapping configured for/url
At this point the browser to access localhost: 8080/rest/path/url to access to the
Experiment 2:
Urlpattern configuration/rest/path that is equivalent to its accurate configuration (note the path/can be behind)
So
@ requetMapping configuration must also be as/rest/path
At this point the browser to access localhost: 8080/rest/path to access to the

CodePudding user response:

reference 1st floor xiafengzhong_12 response:
on the web. The XML configuration when the DispatcherServlet url - the pattern configuration into the following form:
/rest/* & lt;/url - pattern>
1
Methods in the Controller of the above map path configuration into the following several ways:

1./rest/url/url2
The browser enter localhost: 8080/rest/url/url2
Is can't access the resources of
2./url/url2 in the browser to access localhost: 8080/rest/url/url2 can access to
Thinking:
Url - patter/xx/* this form in the map to the controller when * path before cancelling out, * matches only the last one,
Experiment 1:
Urlpattern configuration for the/rest/path/*
@ requetMapping configured for/url
At this point the browser to access localhost: 8080/rest/path/url to access to the
Experiment 2:
Urlpattern configuration/rest/path that is equivalent to its accurate configuration (note the path/can be behind)
So
@ requetMapping configuration must also be as/rest/path
At this point the browser to access localhost: 8080/rest/path to access to the
thank you, I found this problem for a long time, is no good, aha

CodePudding user response:

Positive solution ZZZZZZZZZZ
  • Related