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

  • Home
  • SEARCH
  • 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 8598485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:09:41+00:00 2026-06-12T01:09:41+00:00

I am running into a problem with HttpServlet request. I have an application in

  • 0

I am running into a problem with HttpServlet request. I have an application in which it is to retrieve request headers. If the application finds duplicate header names, it’s supposed to throw an error. However, after a bit of Googling, I found out that HttpServletRequest ignores duplicate header names, and proceeds with getting the first header name it encounters. Is there anything I can do to catch those duplicate request headers?

I’m using Tomcat 6 as the application container.

This is the code:

int headerChecker=0;
for(Enumeration<String>names = request.getHeaderNames(); names.hasMoreElements(); ) {
    String name = (String)names.nextElement();
    if(name.equalsIgnoreCase("abcd")){
        headerChecker++; // add 1 to headerChecker if abcd header is encountered
    }
    for(Enumeration<String>values = request.getHeaders(name); values.hasMoreElements(); ) {
        String value=(String)values.nextElement();
        System.out.println("name: "+name+"\tvalue: "+value);
        }
    }

    if(headerChecker! = 1){
        logger.error("abcd is duplicated, returning HTTP 404");
    } else {
        //...proceed with application
    }
}

Here is the log:

name:  host   value: localhost:8080  name: user-agent value:
CocoaRestClient/8 CFNetwork/520.4.3 Darwin/11.4.2 (x86_64)
(MacBookPro9%2C2)  name: content-length value: 23  name: accept   value:

**name: abcd  value: 1234556**  name: accept-language value: en-us  name: accept-encoding value: gzip, deflate  name: content-type    value:
application/x-www-form-urlencoded  name: connection value: keep-alive

This is the test screenshot:

enter image description here

Edit: Here is the servlet

public class HeaderServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
    doGet(req, res);
}

public void doGet(HttpServletRequest req, HttpServletResponse res)
{
int xmsisdnChecker = 0;
String value = "";  
for(Enumeration<String> names = req.getHeaderNames();names.hasMoreElements();){
    String name = (String) names.nextElement(); 
    Enumeration<String> values = req.getHeaders(name);
    if(values != null)
    {
        while(values.hasMoreElements()) {
            if(name.equalsIgnoreCase("abcd"))
            {
                xmsisdnChecker++;
                System.out.println("ee: " + xmsisdnChecker) ;
            }

            value = (String) values.nextElement();

            System.out.println("header name: " + name + "\theader value: " + value);
        }

    }   
  }
}   
}
  • 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-12T01:09:42+00:00Added an answer on June 12, 2026 at 1:09 am

    No, HttpServletRequest doesn’t ignore duplicate headers – it collects them.

    From HttpServletRequest.getHeaders(String)

    Returns all the values of the specified request header as an Enumeration of String objects.

    Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

    So it sounds like you just need to call getHeaderNames() to retrieve all of the headers that are present, then call getHeaders(String) with each name, and see whether the returned enumeration has more than one entry.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running into a problem. I have a table defined to hold the values of
I'm running into a problem using the jQuery Uploadify plugin in my cakePHP application.
i am running into a problem that i have a jquery modal popup in
I'm running into a problem with JAXB unmarshalling that I have no clue how
I've been running into this problem a lot lately. I have an NSMutableArray called
I keep running into this problem over and over. I have a view with
I have been running into a problem with python's re module. This is the
I'm running into a problem with the MNP package which I've traced to an
I am running into another problem with my Iphone App which I just can't
hey guys m running into a problem, i have a forloop n in that

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.