Spring Jsps and Anchor Jumps

I was wondering if there is a way in Spring to indicate in the controller that I would like to send the client to a specific anchor on the .jsp page that I use for my presentation.

I have a section on my .jsp page identified by the #errors anchor that displays any form errors. I would like to be able to send them directly to this anchor when I need to send them back to .jsp after the model check failed.

Inside my controller classes, I handle these validation errors:

 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 indicate in this block of code that when the client receives the displayed newAdminBookingMenu.jsp back, they are sent directly to the #errors binding #errors on this page.

I obviously cannot do this by simply adding #errors to the .jsp name that I want to display, since InternalResourceViewResolver interprets the view as /WEB-INF/jsp/jspName#errors.jsp , which is clearly incorrect.

I know this can be achieved using javascript and the onload , but I find this view dirty and really prefer the Spring approach, if one exists.

Any ideas?

Greetings.

+4
source share
1 answer

Perhaps a RedirectView is an option:

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

Link:

+8
source

Source: https://habr.com/ru/post/1342021/


All Articles