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 8853269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:36:38+00:00 2026-06-14T13:36:38+00:00

In this period I am studing the Spring MVC Showcase example dowlodable from the

  • 0

In this period I am studing the Spring MVC Showcase example dowlodable from the STS dashboard

I have a doubt related to the functioning of the HTTP Request mapping by header.

In the showcase example I have the following 2 links:

        <li>
            <a id="byHeader" href="<c:url value="/mapping/header" />">By presence of header</a>
        </li>

        <li>
            <a id="byHeaderNegation" class="textLink" href="<c:url value="/mapping/header" />">By absence of header</a>
        </li>

So, as you can see, clicking on the first link I am creating an HTTP request toward the “/mapping/header” folder and clicking on the second link I am creating an HTTP request toward the same “/mapping/header” folder

Now these HTTP requests are managed by two methods in my controller class.

The first one is handled by the following method:

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="FooHeader=foo")
public @ResponseBody String byHeader() {
    System.out.println("Sono dentro byHeder()");
    return "Mapped by path + method + presence of header! (MappingController)";
}

And the second one is handled by the following method:

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="!FooHeader")
public @ResponseBody String byHeaderNegation() {
    System.out.println("Sono dentro byHeaderNegation");
    return "Mapped by path + method + absence of header! (MappingController)";
}

I can not understand why the two requests are handled by two different methods since both links will generate an HTTP request towards the same folder: “/mapping/header”

Why the first one have header and the second one have not?

I’m probably missing something, can you help me to understand this thing?

Thank you very much
Andrea

  • 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-14T13:36:40+00:00Added an answer on June 14, 2026 at 1:36 pm

    As you can find in the src/main/webapp/WEB-INF/views/home.jsp file at the end, the link showing mapping by header, is using Ajax that sets the FooHeader to foo.

    This is how the two methods can be called.

    If you don’t set the header (meaning a simple HTML link), the method byHeaderNegation gets called, but if you set the Header (using Ajax in this case), then the method byHeader gets called because FooHeader=foo is true

    $("#byHeader").click(function(){
        var link = $(this);
        $.ajax({ url: this.href, dataType: "text", beforeSend: function(req) { req.setRequestHeader("FooHeader", "foo"); }, success: function(form) { MvcUtil.showSuccessResponse(form, link); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, link); }});
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this period I am studing the Spring MVC showcase example (downloadable from STS
My IQueryable line is: // find all timesheets for this period - from db
I succeeded to make simple and small example which integrates between Spring MVC and
in this period I am learning Haskell but I have problems solving a simple
i have developed ads website but i have problem, i want make period from
I am trying to have information displayed for this query: SELECT o.sub_number,o.unique_id,o.period_from,o.period_to,o.total_amt, i.paid_amt,i.dated,i.payment,i.paid_by,i.entered_date,i.paid_for_unique, j.cheque_num,j.drawn_on,j.dated
Also is it possible to combine this with removing periods from within the string?
This question is directly related to this SO question I posed about 15 minutes
This should be a simple one: I have an observableArray object called To in
I inherited a horribly-designed table where data is stored like this: Period | Identifier

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.