Remove HTTP Response headers in Java

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

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

Answers


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.

UPDATE

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.


Need Your Help

How do I render a ViewPage to a string?

asp.net-mvc vb.net

I have tried to implement simple ViewPage caching with ASP.NET MVC, however I cannot get the page to render correctly into a custom HtmlTextWriter when it has a master page.

Need clarification about mapping objects to database, annotations, and one to many relationships

java database hibernate annotations persistence

Need some help understanding if I'm on the right track here and exactly what I need to do. Hope someone can chime in.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.