localhost / gwtech / trangchu 에서 localhost / gwtech / search / example으로 제대로 리디렉션 할 수 있지만이 localhost / gwtech / san-pham / example 에서는 localhost / gwtech / san-pham / search로 이동 하지만 localhost / gwtech / search / example 및 show HTTP 상태 405 – 메서드가 허용되지 않음 내 코드 :
<form method="post" action="search" modelAttribute="search" name="search" onsubmit="return validateSearch()">
<div class="form-group">
<input type="text" id="txtsearch" path="tensanpham" name="search-field" value="" placeholder="Nhập tên sẩn phẩm...."/>
<button type="submit"><h1>Find</h1><span class="icon fa fa-search"></span></button>
</div>
</form>
제어 장치
@Autowired
public HomeServiceImpl homeService;
@Autowired
private ProductServiceImpl productService;
@RequestMapping(value = {"/", "/trangchu"})
public ModelAndView home(HttpSession session) {
session.removeAttribute("LoginInfo2");
ModelAndView mv = new ModelAndView("users/index");
mv.addObject("slides", homeService.GetDataSlides());
mv.addObject("loaisp", homeService.GetLoaiSPs());
mv.addObject("nsx", homeService.GetNSXs());
mv.addObject("allsp", homeService.GetSPAlls());
mv.setViewName("users/index");
return mv;
}
@RequestMapping(value = "/search")
public void search(HttpServletRequest request,HttpServletResponse resp, @ModelAttribute("search") String search) throws IOException {
String searchfield = request.getParameter("search-field");
resp.sendRedirect("/gwtech/search/"+searchfield);
}
@Autowired
private DeProductServiceImpl deproductService;
@RequestMapping(value = {"/san-pham","/san-pham/{masp}"}, method = RequestMethod.GET)
public ModelAndView deproduct(HttpSession session,@PathVariable String masp) {
ModelAndView mv = new ModelAndView("users/detail-product");
mv.addObject("loaisp", homeService.GetLoaiSPs());
mv.addObject("nsx", homeService.GetNSXs());
mv.addObject("spbysp", deproductService.GetSPBySP(masp));
mv.addObject("allsp", homeService.GetSPAlls());
mv.setViewName("users/detail-product");
return mv;
}
내가 trangchu에서 검색을 사용했을 때 그것은 매우 잘 실행되지만 san-pham에서는 localhost / gwtech / san-pham / search 로 이동하여 HTTP 상태 405 – 허용되지 않는 메소드를 표시합니다.