我正在使用Spring 3.1.1
和tomcat 5.5.31
cardproducer.jsp文件中的invoke方法:
window.location.href = "${pageContext.request.contextPath}/deleteCardProducer/"
+ id + ".html";
控制器:
@RequestMapping("/deleteCardProducer/{id}")
public String delete(@PathVariable("id") String id, Model model,RedirectAttributes att,HttpServletRequest request)
throws Exception {
if(service.deleteCardProducer(id)){
return getCardProducerList(model,request);
}else{
request.setAttribute("errorMessage", resource.getMessage(
"error.relevantCardProducer", new Object[] {},
LocaleContextHolder.getLocale()));
return "redirect:cardProducer.html";
}
}
删除后应列出所有cardProducers:
@RequestMapping("/cardProducer")
public String getCardProducerList(Model model,HttpServletRequest request) {
model.addAttribute("cardProducerList", service.getAllProducer());
try {
if (request.getParameter("errorMessage")==null) {
return "cardproducer/cardProducer";
}
String errorMessage=new String(request.getParameter("errorMessage").getBytes("ISO-8859-1"), "GBK");
model.addAttribute("errorMessage",errorMessage);
log.info("request.getParameter(errorMessage):"+errorMessage);
} catch (UnsupportedEncodingException e) {
log.error("errors"+e.getMessage());
}
return "cardproducer/cardProducer";
日志信息显示请求URL为cardpro,如下所示:
2014-12-19 16:21:09,997 DEBUG
web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:138) http-8080-2 - queryCardProducer relevant sql String is ~select count(1) from ops_writecardlog t where t.supplier='cardProducer'
2014-12-19 16:21:10,012 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:136) http-8080-2 - deleteCardProducer sql String is ~delete ops_cardproducer where id='cardProducer'
2014-12-19 16:21:10,013 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:138) http-8080-2 - queryCardProducer relevant sql String is ~select count(1) from ops_writecardlog t where t.supplier='cardProducer'
2014-12-19 16:21:10,027 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:136) http-8080-2 - deleteCardProducer sql String is ~delete ops_cardproducer where id='cardProducer'
2014-12-19 16:21:10,029 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:138) http-8080-2 - queryCardProducer relevant sql String is ~select count(1) from ops_writecardlog t where t.supplier='cardProducer'
2014-12-19 16:21:10,043 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:136) http-8080-2 - deleteCardProducer sql String is ~delete ops_cardproducer where id='cardProducer'
2014-12-19 16:21:10,044 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:138) http-8080-2 - queryCardProducer relevant sql String is ~select count(1) from ops_writecardlog t where t.supplier='cardProducer'
2014-12-19 16:21:10,057 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:136) http-8080-2 - deleteCardProducer sql String is ~delete ops_cardproducer where id='cardProducer'
2014-12-19 16:21:10,059 DEBUG web.persistence.HBOPSWebDaoImpl.deleteCardProducer(HBOPSWebDaoImpl.java:138) http-8080-2 - queryCardProducer relevant sql String is ~select count(1) from ops_writecardlog t where t.supplier='cardProducer'
正确的事情是删除cardProducer然后显示所有这些。它会导致无限循环。
答案 0 :(得分:0)
你可以尝试 - modelAndView.setViewName(“redirect:/ cardProducer”);
//在我的项目中,我使用 Tiles 进行模板化
答案 1 :(得分:0)
我认为你的重定向不会回到root。当您通过"redirect:cardProducer.html"
重定向时,我猜测它只是将其附加到您当前的URI,产生类似"/deleteCardProducer/cardProducer.html"
的内容。它正在重定向到这个,由删除控制器拾取,并一次又一次地重定向。
相反,您需要重定向回root。像"redirect:/cardProducer.html"
这样的开头斜线的东西。
您应该能够在浏览器中打开控制台,看看位置标头值是什么(重定向URI)。