简体   繁体   English

删除Java中的HTTP响应标头

[英]Remove HTTP Response headers in Java

Is there a way to remove HTTP response headers like Server and X-Powered-By? 有没有一种方法可以删除HTTP响应标头,例如Server和X-Powered-By?

My application is using a Weblogic server. 我的应用程序正在使用Weblogic服务器。 I'm programming in Java using the Spring MVC framework and Hibernate, and using JSP for views. 我正在使用Spring MVC框架和Hibernate进行Java编程,并使用JSP进行视图。

Depends on where the headers are added. 取决于标题的添加位置。 If inside your app, you can use a Spring MVC Interceptor to remove them after your controller calls. 如果在应用程序内部,则可以在控制器调用后使用Spring MVC拦截器将其删除。 If outside your app, you might be able to try a Java EE filter configured in web.xml (the example is security, but the approach will also work for your use case). 如果在应用程序外部,则可以尝试在web.xml中配置的Java EE过滤器 (示例是安全性,但是该方法也适用于您的用例)。 If its added after that, you may want to look at your web front end (Apache, IIS, what-have-you) to configure a filter there. 如果在此之后添加了它,则可能要查看Web前端(Apache,IIS,必备工具)以在其中配置过滤器。

UPDATE UPDATE

This answer describes an approach for removing specific headers, as the HttpServletResponse interface does not allow for header removal explicitly. 该答案描述了一种删除特定标头的方法,因为HttpServletResponse接口不允许显式删除标头。 You will need some trial and error to determine what portion of your stack is adding the header. 您将需要反复试验才能确定堆栈的哪个部分正在添加标头。

如果将具体的responseHeader设置为null ,它将被删除/在响应头中看不到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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