简体   繁体   中英

Why aren't my JSP pages outputting a content-length?

I have configured CloudFront in front of my web application that uses JSP pages, but it will not cache my page because the Content-Length header is not set.

Is there a way that I can get JSP to include the Content-Length, or do I need to do something ugly like have a filter than streams the content to determine it's length, then streams it to the response stream afterwards (setting the ContentLength header first).

You can set Content-Length using JSP's HttpServletResponse

The response object is an instance of a javax.servlet.http.HttpServletResponse object.

We can use the following methods to set HTTP response header in your servlet program.

Call setContentLength method

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

我找到了一种方法,可以使用适合我需要的过滤器 ,甚至可以先处理JSP除去空格,然后将其结果链接到ContentLengthFilter中。

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