在Java中删除HTTP响应标头 [英] Remove HTTP Response headers in Java

查看:2535
本文介绍了在Java中删除HTTP响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法删除HTTP响应标头,如Server和X-Powered-By?

Is there a way to remove HTTP response headers like Server and X-Powered-By?

我的应用程序正在使用Weblogic服务器。我使用Spring MVC框架和Hibernate在Java中编程,并使用JSP进行视图。

My application is using a Weblogic server. I'm programming in Java using the Spring MVC framework and Hibernate, and using JSP for views.

推荐答案

取决于标题的位置添加。如果在你的应用程序中,你可以使用 Spring MVC Interceptor 在控制器调用后删除它们。如果在您的应用之外,您可以尝试 Java EE过滤器(示例是安全性,但该方法也适用于您的用例)。如果在此之后添加,您可能需要查看您的Web前端(Apache,IIS,有什么你)在那里配置过滤器。

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. 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). 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.

更新

此答案描述了一种删除特定标头的方法,因为HttpServletResponse接口不允许明确删除标头。您将需要一些试验和错误来确定堆栈的哪个部分正在添加标题。

This answer describes an approach for removing specific headers, as the HttpServletResponse interface does not allow for header removal explicitly. You will need some trial and error to determine what portion of your stack is adding the header.

这篇关于在Java中删除HTTP响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆