1
我將表單發送到服務器,一旦表單成功我想重定向到另一個頁面,但是我想將值發送到具有GET請求的重定向頁面。我沒有得到的值傳遞:Spring MVC嘗試從GET請求方法中獲取參數重定向
錯誤 我得到一個HTTP 400錯誤的請求錯誤
代碼
@RequestMapping(value = "crime_registration_save.htm", method = RequestMethod.POST)
public ModelAndView handleSave(@Valid @ModelAttribute Crime crime,BindingResult result, ModelMap m, Model model) throws Exception {
if (result.hasErrors()) {
logger.debug("Has Errors In crime_registration_save");
model.addAttribute("dbcriminals", myCriminalList);
model.addAttribute("dbvictims", myVictimList);
model.addAttribute("status", myStatusList);
model.addAttribute("crimeCategory", myCrimeCategoryList);
model.addAttribute("crimeLevel", myCrimeLevelList);
model.addAttribute("officers", myOfficerList);
model.addAttribute("victimList", crime.getVictims());
model.addAttribute("criminalList", crime.getCriminals());
model.addAttribute("crimeTypeList",
crimeTypeManager.getCrimeTypeList(crime.getOffenceCatId()));
model.addAttribute("icon", "ui-icon ui-icon-circle-close");
model.addAttribute("results", "Error: Unable to Save Record!");
return new ModelAndView("crime_registration");
}
logger.debug("No errors going to preform save");
int crimeRecNo;
crimeRecNo = crimeManager.saveCrime(crime);
return new ModelAndView(new RedirectView("monitoringList.htm"));
}
//-----------------------------------------------------------------------------------------
@RequestMapping(value = "monitoringList.htm", method = RequestMethod.GET)
public ModelAndView handleMonitoring(@RequestParam(value="crimeRecNo", required=true) Integer crimeRecNo, HttpServletRequest request,
HttpServletResponse response ,Model model) throws Exception {
model.addAttribute("crimeRecNo", crimeRecNo);
return new ModelAndView("monitoringList");
}
有沒有一種方法可以隱藏用戶在url中的參數,所以他們不會看到crimeRecNo? – devdar 2013-04-27 17:41:05
您可以隱藏參數的唯一方法是使用hacky sesion scope屬性方法。我把它稱爲hacky,因爲它是直觀的。在發佈後,呈現GET請求的原因是確保用戶獲得冪等URL。用戶可以加載多次的url,沒有任何負面影響。如果這個GET鏈接不包含它試圖獲取的數據的id,但是它依賴於會話屬性,那麼url不再是冪等的。如果用戶稍後加載URL,它甚至可能不工作,或指向會話中當前的記錄。 – Akshay 2013-04-29 12:01:25
我試着加密參數值,但我遇到了一些問題,你可以看看這個給我http://stackoverflow.com/questions/16259118/encryption-and-decryption-using-blowfish-error-input-length-must-待多個鄰 – devdar 2013-04-29 12:29:12