我有这个 servlet 映射
<servlet-mapping>
<servlet-name>devicesWeb</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>/device-catalogue</url-pattern>
<url-pattern>/device-catalogue/</url-pattern>
<url-pattern>/device-catalogue/*</url-pattern>
<url-pattern>/search/search.do</url-pattern>
</servlet-mapping>
使用这两种方法:
@RequestMapping(value = "/device-catalogue", method = RequestMethod.GET)
private String initForm(@ModelAttribute("searchForm") final SearchForm searchForm,
BindingResult result, HttpServletRequest request, Model model, Locale locale) {
sessionHelper.checkSessionAttributes(request, locale);
return SEARCH_VIEW;
}
@RequestMapping(value = { "/search/showProductDetails.do", "/device-catalogue/{id}" }, method = { RequestMethod.GET, RequestMethod.POST })
private String showProductDetails(@ModelAttribute("searchForm") final SearchForm searchForm,
HttpServletRequest request, Model model, Locale locale) {
StringTokenizer st = new StringTokenizer(StringEscapeUtils.escapeHtml(searchForm.getItemId()),"=");
if (st.countTokens()>1) {
String awardId=st.nextToken();
String id=st.nextToken();
Item item = deviceService.getItemByAwardId (Long.parseLong(id), awardId);
normalizeWebsiteURL (item);
orderCountriesAvailability(item.getCountriesAvailability(), locale);
model.addAttribute("item", encodeItemForHTML(item));
}
return PRODUCT_DETAIL_VIEW;
}
此 URL 工作正常:
http://127.0.0.1:7001/eDevices/device-catalogue
但不是这个(我有一个 404)!
http://127.0.0.1:7001/eDevices/device-catalogue/16720
如果我将它添加到 web.xml 它可以工作
<url-pattern>/product-catalogue/16720</url-pattern>