@RequestMapping(method=RequestMethod.POST) public ModelAndView addIntake(@ModelAttribute("intake")Intake intake, BindingResult result){ // Validate Intake command object and persist to database // ... String caseNumber = assignIntakeACaseNumber(); RedirectView rv = new RedirectView("redirect:intakeDetails.htm?caseNumber=" + caseNumber); rv.setExposeModelAttributes(false); return new ModelAndView(rv); }
public ModelAndView redirectToSomewhere() { RedirectView redirectView = new RedirectView("/my/form/newpage.html?pid=".concat(myform.getId().toString()); redirectView.setExposeModelAttributes(false); // these redirectView.setExposePathVariables(false); //two depend on the way you set your variables return new ModelAndView(redirectView); }
public static RedirectView safeRedirect(String url) { RedirectView rv = new RedirectView(url); rv.setExposeModelAttributes(false); return rv; }
@Override public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) { if (modelAndView != null && StringUtils.isNotBlank(request.getQueryString()) && request.getQueryString().contains(CasProtocolConstants.PARAMETER_TICKET)) { val v = new RedirectView(request.getRequestURL().toString()); v.setExposeModelAttributes(false); v.setExposePathVariables(false); modelAndView.setView(v); } } }
@Override public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) { if (!StringUtils.isEmpty(request.getQueryString()) && request.getQueryString().contains(CasProtocolConstants.PARAMETER_TICKET)) { val view = new RedirectView(request.getRequestURL().toString()); view.setExposeModelAttributes(false); view.setExposePathVariables(false); modelAndView.setView(view); } }
private RedirectView redirectViewWithQuery(String redirectUri, String state, String query) { try { if (!Strings.isNullOrEmpty(state)) { query += "&state=" + state; } String encoded = UriUtils.encodeQuery(query, Charsets.UTF_8.name()); String locationUri = redirectUri; if (redirectUri.contains("?")) { locationUri += "&" + encoded; } else { locationUri += "?" + encoded; } RedirectView redirectView = new RedirectView(locationUri); redirectView.setStatusCode(HttpStatus.FOUND); redirectView.setExposeModelAttributes(false); redirectView.setPropagateQueryParams(false); return redirectView; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
private Object resolveZone(HttpServletRequest request, String decodedRawZone, Function<ZoneInfo, ModelAndView> onZoneInfo) { // note that decodedRawZone already do http url decode, and PathVariable already trim() // space of value return Zone.tryFallback(decodedRawZone).map(zone -> { if (!zone.value().equals(decodedRawZone)) { String orgUrl = request.getRequestURL().toString(); // replace pattern is combine of fallback pattern and valid pattern // TODO refactor replace rule to Zone String location = orgUrl.replaceFirst("/z/[a-zA-Z0-9_\\-]+", "/z/" + zone); //check if fallback success, this prevent infinite redirect loop if (!location.equals(orgUrl)) { RedirectView redirectView = new RedirectView(location); redirectView.setPropagateQueryParams(true); redirectView.setExpandUriTemplateVariables(false); redirectView.setExposeModelAttributes(false); redirectView.setExposeContextBeansAsAttributes(false); redirectView.setExposePathVariables(false); redirectView.setContextRelative(true); redirectView.setStatusCode(HttpStatus.PERMANENT_REDIRECT); return redirectView; } } return onZoneInfo.apply(zoneService.loadZone(zone)); }).orElseThrow(() -> new EmptyResultDataAccessException("no such zone: " + decodedRawZone, 1)); }