Open joealbertvp opened 10 years ago
This happens when your servlet is configured as <url-pattern>/</url-pattern>
instead of <url-pattern>/*</url-pattern>
(notice the asterisk).
The code you mention is correct for the case when your url-pattern is more sophisticated, such as /app/place/*
, where you would want to prepend the servlet.servletPath to your contextPath. However, the specification for mappings states:
Thus, a case for handing the 3rd rule there must be encoded. Scalatra seems to have the same problem currently (see https://github.com/scalatra/scalatra/issues/392)
Could one of you submit a PR with a test and/or a fix for this?
I'm using spring mvc 4 with thymeleaf,
i can configure thymeleaf using RouterModelAttribute in this way i have access in my view to the router with default name 'route'
My routes.conf content:
When i do ${route.reverse('testController.foo')} it give me the value of '/test/1/test/1' which is wrong url, i expect to /test/1 which is the value mapped to testController.foo.
I have looked to the code in the reverse method:
String path = route.path; if( currentRequest != null) { if(!currentRequest.servletPath.isEmpty() && !currentRequest.servletPath.equals("/")) { String servletPath = currentRequest.servletPath; path = (servletPath.startsWith("/") ? servletPath : "/" + servletPath) + path; }
\ by removing this code the reverse method works as i should expect: if(!currentRequest.servletPath.isEmpty() && !currentRequest.servletPath.equals("/")) { String servletPath = currentRequest.servletPath; path = (servletPath.startsWith("/") ? servletPath : "/" + servletPath) + path;
}
Could you confirm this issue?