【问题标题】:Spring ModelAndView set request header valuesSpring ModelAndView 设置请求头值
【发布时间】:2014-08-06 16:27:54
【问题描述】:

有什么方法可以为 spring ModelAndView 设置一些标头值。确切的问题如下。

final String confirmationUrl = details.getConfirmationUrl() + details.getOrderAttemptUuid();
final ModelAndView modelAndView = new ModelAndView(new RedirectView(confirmationUrl));

我正在创建一个新模型和视图,但想将引用标头设置为某个特定值。有没有办法做到这一点?

原因是当我从 https 页面访问并重定向到 https 时,引用者保留在请求中,但是当我从 https 访问但重定向到 http 时,我丢失了引用者

http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3

有什么方法可以将referer保留在请求中或将其设置回ModelAndView?

【问题讨论】:

    标签: java spring spring-mvc servlets request


    【解决方案1】:

    考虑可能从您的请求映射中返回一个 ResponseEntity。

    http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html

    然后你可以像这样设置响应头:

    @RequestMapping("/handle")  public ResponseEntity<String> handle() { 
        HttpHeaders responseHeaders = new HttpHeaders();   
        responseHeaders.set("MyResponseHeader", "MyValue");
        return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
    }
    

    【讨论】:

      【解决方案2】:

      能不能用ModelAndView上的addObject(name, value)方法来存储?

      http://docs.spring.io/spring/docs/3.2.x/javadoc-api/org/springframework/web/servlet/ModelAndView.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-09
        • 1970-01-01
        • 2020-06-25
        • 2013-10-14
        • 2015-10-31
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        相关资源
        最近更新 更多