重定向后如何保持请求参数?
我试图解决一个错误,当我发送一个空输入的窗体。
这是我梅索德:
@RequestMapping(value = "/modifier.html", method = RequestMethod.POST)
public String modifier(ModelMap map, @ModelAttribute("FormObject") FormObject formObject, BindingResult result, HttpServletRequest req) {
formObject.setModif(true);
String idParam = req.getParameter("idTypeOuverture");
if (result.hasErrors()) {
return "redirect:/gestion.html?section=Configuration&panel=4&ouvrir=modifier";
} else {
//Instructions
}
当有错误(空输入)控制器重定向到这个链接,告诉用户纠正错误。问题是,当我检查参数,在这里,他们看起来是正确的(ID,姓名...),但在以下方法ID变为零:为什么参数ID redericting后改变
@Override
public ModelAndView dispatcher(HttpServletRequest request, HttpServletResponse response) throws RorException {
Map<String, Object> myModel = (Map<String, Object>) request.getAttribute(EnumParam.R_MY_MODEL.getKey());
Enumeration<?> keys = request.getParameterNames();
while (keys.hasMoreElements()) {
String paramName = (String) keys.nextElement();
String value = request.getParameter(paramName);
myModel.put(paramName, value);
}
GlobalSession globalSession = (GlobalSession) getApplicationContext().getBean(Utilities.GLOBALSESSION_BEAN_REF);
myModel.put("module", globalSession.getModule().getKeyMessage());
String section = request.getParameter("section");
// This instruction returns null
String idForm = request.getParameter("id");
id = Integer.parseInt(idForm);
// This instruction returns NumberFormatException
ObjectForm of = getForm(id);
// ...
}
好了,我不知道?你有什么主意吗?我尝试在第一个方法中重新设置参数,但仍然得到相同的NFE。
预先感谢您。
谢谢