简体   繁体   中英

Setting headers in RedirectView in Java

I am new in Java, In our application we are using RedirectView for redirecting to particular URL. My question here is there any way by which I can set Headers to this RedirectView Url. As we need to send some data at the redirected Page. I know its a silly question, I have just started studying Java :) Regards, Manish

springboot

RedirectView redirectView = new RedirectView("redirect:/users");
    redirectView.setPropagateQueryParams(true);
    return redirectView;

You can set using response . I have taken the example for file attachment.

 @RequestMapping(value="",method=RequestMethod.Method)
    public myMethod(HttpServletResponse response) throws IOException
    {
        response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename);
        response.setContentType("application/XXX");         
    }

You can set the following methods to set response Header

  • void setHeader(String name, String value)
  • void addDateHeader(String name, long date)
  • void addHeader(String name, String value)
  • void addIntHeader(String name, int value)
  • String encodeRedirectURL(String url)
  • String encodeURL(String url)
  • void addCookie(Cookie cookie) ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM