getting org.springframework.web.bind.MissingServletRequestParameterException
I am using spring annotations I have written one method
public ModelAndView showTest开发者_如何学CPage(@RequestParam("firstInstanceId") String id1,
@RequestParam("secondInstanceId") String id2, HttpSession session) {
ModelAndView mv = new ModelAndView("showCompareItemList");
mv.addObject("pageTitle", "showCompareItemList");
mv.addObject("firstInstanceId", id1);
mv.addObject("secondInstanceId", id2);
return mv;
}
when there both values of id1 and id2 are present it works fine but when there is only one value i get exception org.springframework.web.bind.MissingServletRequestParameterException: Required java.lang.String parameter 'secondInstanceId' is not present I tried resolve this problem by checking null but still i am getting this exception can anybody tell me what should I do to avoid this excpetion?
If request parameter may be missed, mark it with required = false
:
public ModelAndView showTestPage(@RequestParam("firstInstanceId") String id1,
@RequestParam(value = "secondInstanceId", required = false) String id2,
HttpSession session) {
...
}
精彩评论