jstl url标记生成错误的url

时间:2015-11-11 00:17:46

标签: jsp spring-mvc jstl

我正在尝试使用此url将请求发送到我的Spring MVC控制器映射:

 @RequestMapping(value = "/place/{placeId}/menu/service", method = RequestMethod.POST)
public String registerNewPlaceMenuService(@Valid ServiceDTO serviceDTO,
                                          @PathVariable("placeId") long placeId,
                                          BindingResult result) {
    if(!result.hasErrors()) {
        PlaceUser user = userService.placeUser();
        Place place = placeService.getOwnerPlace(placeId, user);
        if (place != null) {
            PlaceMenu menu = dao.getMenuById(serviceDTO.getMenuId());
            if (place.getPlaceMenu().contains(menu)) {
                placeService.registerNewPlaceMenuService(menu, serviceDTO);
            }
        }
    }
    return "redirect:place/" + placeId;
}

这就是我使用jstl url标签的方式:

<c:url context="/" value='/place/${place.id}/menu/service'
var="newservice"/>
<sf:form modelAttribute="service" action="${newservice}" method="post">

这就是我得到的:

http://localhost:8080/place/30/menu/place/30

我甚至不知道最后一个“/ service”部分去了哪里! 我发送请求的页面有此URL

http://localhost:8080/place/30

帮助!

1 个答案:

答案 0 :(得分:0)

试试这个:

@RequestMapping(value = "/place/{placeId}/menu/service", method =
 RequestMethod.POST)