Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:03:47+00:00 2026-06-14T00:03:47+00:00

I need to modify this header based on page contents. eg: this is a

  • 0

I need to modify this header based on page contents.

eg: this is a contrieved example-since it was requested. I cannot go into the details of the specific header
The servlet/page sets a header specialheader=xyz based on what backend system was accessed. If this specialheader is set the filter will modify it to xyz+abc. If the header is not set, the filter will set it to 123.

I could use a filter to create a wrapped HttpServletResponse and modify it on its way back. However, I am fuzzy on the details.

I know I have to prevent the output from being sent back to client before my filter does its job. In order to do this, do I need to pass it my own OutputStream and buffer the output?

Do I really need to do that ? can I avoid buffering the output which may put load on the server

The basic question is- if I need to modify the header AFTER the doFilter call, what is the minimum do I need to do ?
Is there some other way of preventing the output from being committed such as overriuciding flush etc., ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:03:48+00:00Added an answer on June 14, 2026 at 12:03 am

    Just implement getHeader and getHeaderNames to ignore the header you want to discard and set the Wrapper as a filter.

    import java.io.ByteArrayOutputStream;
    import java.io.PrintWriter;
    import java.util.Collection;
    
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpServletResponseWrapper;
    
    public class GenericResponseWrapper extends HttpServletResponseWrapper {
    
    
    
        public GenericResponseWrapper(final HttpServletResponse response) {
            super(response);    
        }
    
        @Override
        public String getHeader(String name) {
            // TODO Auto-generated method stub
            return super.getHeader(name);
        }
        @Override
        public Collection<String> getHeaderNames() {
            // TODO Auto-generated method stub
            return super.getHeaderNames();
        }
    }
    
    
    public class Wrapper implements Filter {
    
        @Override
        public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
            final HttpServletRequest httpRequest = (HttpServletRequest) request;
            final HttpServletResponse httpResponse = (HttpServletResponse) response;
                final GenericResponseWrapper wrapper = new GenericResponseWrapper(httpResponse);
                wrapper.getResponse().setCharacterEncoding("UTF-8");
    
                chain.doFilter(request, wrapper);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes I need to modify a third party library for my specific needs. It
I need to be able to append an HTTP header (or modify the user
I need to modify an existing script which uses SED to search and replace
I need to modify an MSI file, and I'd like to do it in
I need to modify the lm (or eventually loess ) function so I can
I need to modify a php search script so that it can handle multiple
I need to modify a column in a SQLite database but I have to
I need to modify a text file from multiple .NET processes, nothing I've tried
I need to modify a regular expression that matches a url for a redirect.
I need to modify the display of elements in my razor view depending on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.