开发者

Spring Jsps and Jumping to Anchors

I was wondering if there is some way in Spring to specify in the controller that I would like to send the client to a specific anchor within the .jsp page that I am using for my view.

I have a section in my .jsp page, identified by an #errors anchor, that displays any form errors that occur. I would like to be able to send them directly to that anchor whenever I need to send them back to the .jsp after model validation fails.

Inside my controller classes, I handle validation errors like so:

if (result.hasErrors())
        {

            for (ObjectError error : result.getAllErrors())
            {

                logger.debug("Validation Error: " + error.getDefaultMessage());
            }

            ModelAndView mv = new ModelAndView();

            mv.setViewName("/secure/formViews/newAdminBookingMenu");
            mv.addObject(BindingResult.MODEL_KEY_PREFIX + "booking", result);

            return mv;
        }

I would like to be able to specify in that code block that when the client gets the rendered newAdminBookingMenu.jsp back that they are sent directly to the #errors anchor tag within that page.

I obviously cannot do this by just adding #errors to the name of the .jsp i wish to render as the InternalResourceViewResolver will interpret the view as /WEB-INF/jsp/jspName#errors.jsp which is clearly inc开发者_如何学Pythonorrect.

I know this can be accomplished with javascript and the onload event but I find that kind of dirty and would really rather find a Spring approach if one exists.

Any ideas?

Cheers.


Perhaps a RedirectView is an option:

modelAndView.setView(new RedirectView("error/page#errors", true));

Reference:

  • 15.5.3.1 RedirectView
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜