Restful Path Parameters in Spring MVC 3

前端 未结 2 1545
南旧
南旧 2021-01-13 00:51

Is it possible to: set a URI template in the mvc:view-controller element of the *-servlet.xml file or in a controller method and then use/get that path parameter in a js

相关标签:
2条回答
  • 2021-01-13 01:18

    The Map of resolved path variables is exposed as an attirubte with name specifed by HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE. So, the solution is

    <c:if test="${not empty requestScope['org.springframework.web.servlet.HandlerMapping.uriTemplateVariables']['error']}">
    

    But accessing it this way is probably not a best idea, Affe's solution is cleaner.

    0 讨论(0)
  • 2021-01-13 01:21

    If you want access to it in the jsp, return it as an attribute from the controller:

    @RequestMapping("/home/{error}")
    public void handleError(@PathVariable String error, ModelMap model) {
        //your regular stuff
    
        model.addAttribute("error", error);
    }
    

    -

    <c:if test="${not empty error}">
    <span class="error">You have an error...</span>
    </c:if>
    
    0 讨论(0)
提交回复
热议问题