0

我有一个页面,我输入参数来查询记录列表。当单击查询按钮时,当单击列表中的项目时,我会得到列表,它会将我带回到显示记录的第一页。

当我点击另一个按钮' new '来清除页面并返回一个空页面时,url中有一个参数,它设置页面上一个项目的值。url中的项目是crimeRecNo。

我怎样才能摆脱这个我想返回一个空页面?

设想

  1. 我在带有以下网址的页面上:http://adomain/crimeTrack/crime_registration.htm

  2. 我单击查询,它对另一个显示记录列表的 url 进行 POST:http://adomain/crimeTrack/crimeList.htm

  3. 然后在上面 2 中的页面上,我选择一个执行 POST 并将我带到以下 URL 的记录:http://adomain/crimeTrack/getCrime/6.htm - where 6 is the crimeRecNo.

  4. 我现在在上面的 url 上,我点击“NEW”按钮得到一个空白表格,上面有 1 中的 url。当我点击新时,对代码示例 4中的控制器方法执行 POST

此方法重定向到映射到 GET 方法的 url,但最终 url 看起来像这样:http://adomain/crimeTrack/%20crime_registration.htm?crimeRecNo=6

值 6 保留在 crimeRecNo 字段中,并且不清除整个表单。

下面是控制器方法:

1.初始页面请求

@RequestMapping(value = "crime_registration.htm", method = RequestMethod.GET)
public ModelAndView loadPage(HttpServletRequest request,HttpServletResponse response, @ModelAttribute Crime crime,BindingResult result, ModelMap m, Model model, SessionStatus status,HttpSession session) throws Exception {

            try {


                logger.debug("In Crime Registration Controller");

                myCriminalList.put("dbcriminalList",
                        this.citizenManager.getListOfCriminals());
                ...................

                session.setAttribute("page", 0);


                return new ModelAndView("crime_registration");

            } catch (Exception e) {

                logger.debug("Exception In CrimeRegistration Controller : "
                        + e.getMessage());

                return new ModelAndView("crime_registration");

            }

        }

2.查询项目列表

@RequestMapping(value = "crimeList.htm", method = RequestMethod.POST)
public ModelAndView handelCrimeList(@ModelAttribute Crime crime,
        BindingResult result, ModelMap m, Model model) throws Exception {

    if (crimeManager.getCrimesList(crime).size() <= 0) {

        model.addAttribute("dbcriminals", myCriminalList);
        ........

        model.addAttribute("crimeTypeList", crimeTypeManager.getCrimeTypeList(crime.getOffenceCatId()));

        model.addAttribute("icon", "ui-icon ui-icon-circle-close");
        model.addAttribute("results","Error: Query Caused No Records To Be Retrieved!");

        return new ModelAndView("crime_registration");
    }

    model.addAttribute("crimes", crimeManager.getCrimesList(crime));

    return new ModelAndView("crimeList");

}

3. 请求一个项目/从列表中选择项目时

@RequestMapping(value = "getCrime/{crimeRecNo}.htm", method = RequestMethod.POST)
public ModelAndView getCrime(@PathVariable Integer crimeRecNo,
        @ModelAttribute Crime crime, BindingResult result, ModelMap m,
        Model model, HttpServletRequest request,
        HttpServletResponse response, HttpSession session) throws Exception {

    try {
        model.addAttribute("crime", crimeManager.getCrimeRecord(crimeRecNo));
        session.setAttribute("crimeRecNo", crimeRecNo);
        //model.addAttribute("victimList", citizenManager.getVictimListByCrimeRecNo(crimeRecNo));

    } catch (Exception e) {

        logger.error("Exception in CitizenRegistrationController - ModelAndView getCitizen "
                + e);
    }

    int crimeCatId = crimeManager.getCrimeRecord(crimeRecNo).getOffenceCatId();
    logger.info("crime category number is : "+crimeCatId);  

    myCrimeTypeList.put("crimeTypeList", this.crimeTypeManager.getCrimeTypeList(crimeCatId));


    model.addAttribute("dbcriminals", myCriminalList);
    .....
    session.setAttribute("crimeRecNo", crimeRecNo);

    return new ModelAndView("crime_registration");


}

4. 申请新表格

@RequestMapping(value = "crime_registration_new.htm", method = RequestMethod.POST)
public String loadNew(HttpServletRequest request,Model model,
        HttpServletResponse response,SessionStatus status,HttpSession session) throws Exception {

    status.setComplete();


    return "redirect: crime_registration.htm";
    //return new ModelAndView(new RedirectView("crime_registration.htm")); 


}
4

1 回答 1

0

将此添加到 4 就可以了

@RequestMapping(value = "crime_registration_new.htm", method = RequestMethod.POST)
public String loadNew(HttpServletRequest request,Model model,
        HttpServletResponse response,SessionStatus status,HttpSession session) throws Exception {

    status.setComplete();

  model.addAttribute("crime", new Crime());
    return "redirect: crime_registration.htm";
    //return new ModelAndView(new RedirectView("crime_registration.htm")); 


}  
于 2013-05-02T22:39:04.120 回答