簡體   English   中英

將HTTP標頭添加到index.html的響應中

[英]Add HTTP header into response for index.html

在JavaEE應用程序中。
我在web.xml中將index.html頁面作為“welcome-file”

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

我想將Http Header添加到index.html的響應中

一種方法是使用index.jsp而不是index.html並在scriptlet中添加:

<% response.addHeader("X-Frame-Options", "DENY");  %>

還有其他方法嗎? 是否有可能添加某種過濾器
例如:

WelcomeFileFilter {
  void filter(HttpServletResponse response) {
    response.addHeader("X-Frame-Options", "DENY");
  }
} 

因為我不想使用index.jsp而不是index.html。

你絕對可以添加一個過濾器,

嘗試 - responseheaderfilter

您可以要求您的Web服務器/ servlet容器為您添加這些標頭。 它將在服務器配置文件中配置,而不是在web.xml中。

或者,您可以創建一個過濾器,為您添加標題。 您必須在web.xml中配置過濾器。

stackoverflow答案向您展示如何配置jetty以添加標頭。 此另一個stackoverflow答案向您展示了如何編寫添加標頭的Filter。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM