Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the download file name is invalid for response.setHeader settings

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains how to solve the problem of "response.setHeader setting download file name invalid". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "response.setHeader setting download file name invalid" together.

response.setHeader setting download filename invalid response.setContentType("application/octet-stream");response.setHeader("Content-Disposition", "attachment; filename=down.xls");

After setting, click the download file name invalid, is the name of the method

solve

Put the above code in front of the stream.

response.setheader is invalid

Recently, when building the architecture, we used HandlerInterceptorAdapter.

response.setHeader("token", token) is used in afterCompletion or postHandle;

The idea was to return a new jwt token to the caller after the method execution was complete.

However, the actual return does not get the value of set.

reason is

Response header settings, to load the buffer before the response content, http protocol is in accordance with the response status line, the response header and response body output order, after the header does not take effect. Therefore, writing a header in the preHandle can take effect.

output buffer

The response body of the HTTP message output by the Servlet program is first written to an output buffer provided by the Servlet engine, and the contents of the buffer will not be sent to the client by the Servlet engine until the output buffer is filled or the Servlet program has written all the response contents.

After using the output buffer, the Servlet engine can adjust the response status line, each response header and response body strictly according to the position order of the HTTP message before outputting it to the client.

If all the response content is loaded in the output buffer when the response is submitted to the client, the Servlet engine calculates the size of the response body and automatically sets the Content-Length header field.

If the output buffer is loaded with only a portion of the total response content when the response is submitted to the client, the Servlet Engine will transmit the response content using HTTP 1.1 chunked encoding (specified by setting the Transfer-Encoding header field).

Thank you for reading, the above is "response.setHeader set download file name invalid how to solve" the content, after the study of this article, I believe that we have a deeper understanding of response.setHeader set download file name invalid how to solve this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report