我在jsp和控制器中有一个包含4个buttoms(保存,删除,搜索,更新)的POST表单。
控制器中保存,更新和删除的方法可以正常工作:
@RequestMapping(value="/myPage.htm",params = "delete", method = RequestMethod.POST)
public void delete(HttpServletRequest request) {
//Construct item to save
this.itemService.deleteItem(item);
}
但问题是搜索方法。我尝试了几种方法:
@RequestMapping(value="/myPage.htm",params = "search", method = RequestMethod.POST)
public ModelAndView search(@RequestParam(value="e1", required=false) String calle,
@RequestParam(value="e2", required=false) String e1,
@RequestParam(value="e3", required=false) String e2,
@RequestParam(value="e3", required=false) String e3,
HttpServletRequest request, HttpServletResponse response
){
//convert e2 to Integer
//construct the ModelAndView with the list the items
...}
返回页面在所有情况下都是相同的,但在搜索案例中,表单(唯一表单)元素是使用项目列表中的信息完成的。
重点是我收到错误:请求方法'get'不受支持。
任何帮助?
非常感谢你!
如果我改为Gest,我会收到错误: [http-nio-8080-exec-3] WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - 处理程序执行导致异常:参数条件“搜索”未满足实际请求参数:(我什么都没得到)更多错误日志)
我在控制器中的方法是:
@RequestMapping(value="/myPage.htm",params = "search", method = RequestMethod.GET)
public ModelAndView search(@RequestParam(value="e1", required=false) String e1, @RequestParam(value="e2", required=false) String e2, @RequestParam(value="e3", required=false) String e3, @RequestParam(value="e4", required=false) String e4, HttpServletRequest request, HttpServletResponse response){
//convert e2 to Integer
myModel = new HashMap<String, Object>();
List<Item> items= this.itemService.getItems(e1,e2b,e3,e4);
myModel.put("items", items);
} catch(Exception e){
e.printStackTrace();
}
return new ModelAndView("item", "model", myModel);
}
}
在jsp中我有:
<form:form method="post" action="MyPage.htm">
E1: <input name="e1" size="30"></input>
E2: <input name="e2" size="30"></input>
E3: <input name="e3" size="30"></input>
E4: <input name="e4" size="30"></input>
<button type="submit" name="save" style="width: 100px;"><span>Save</span></button>
<button type="submit" name="delete" style="width: 100px;"><span>Delete</span></button>
<button type="submit" name="update" style="width: 100px;"><span>Update</span></button>
<button type="submit" name="search" style="width: 100px;"><span>Search</span></button>
而且,现在(只是为了尝试代码):
<c:forEach items="${model.items}" var="item">
<c:out value="${item.getData()}" />
</c:forEach>
答案 0 :(得分:0)
变化:
@RequestMapping(value="/myPage.htm",params = "search", method = RequestMethod.GET)
要
@RequestMapping(value="/myPage.htm",params = "search", method = RequestMethod.POST)