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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:55:58+00:00 2026-06-09T09:55:58+00:00

In Spring MVC (I’m working with 3.0.2), two HTTP methods are always (or mostly

  • 0

In Spring MVC (I’m working with 3.0.2), two HTTP methods are always (or mostly as it seems to me) reserved (i.e. mapped with appropriate handlers) which are GET and POST such as

@RequestMapping(method=RequestMethod.GET)
public String showForm(Map model)
{
     //Usually retrieve data from the database when the page is loaded.

     return "admin_side/Temp";
}

The above method is invoked when a GET request is made.


@RequestMapping(method=RequestMethod.POST)
public String onSubmit(@ModelAttribute("tempBean") @Valid TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response)
{
     //Perform some basic operations with the database like insert, update or delete when the form is submitted (by clicking a submit button or so).

     return "admin_side/Temp";
}

The above method is invoked when a POST request is made. Assuming that the Spring controller is designated with the @RequestMapping(value="admin_side/Temp") annotation.


Now, what happens, if I need to use Ajax and I need to perform different functionality than the preceding methods do? I can neither handle another method with the GET method nor with the POST method because there are already handlers mapped (both the HTTP methods, GET and POST are reserved to handle the showForm() and onSubmit() methods respectively).

For the sake of demonstration, I used the method=RequestMethod.PUT approach with Ajax such as

@RequestMapping(method=RequestMethod.PUT)
public @ResponseBody String getStateList(@ModelAttribute("tempBean") @Valid TempBean tempBean, BindingResult error, HttpServletRequest request, HttpServletResponse response)
{
    return "Message";
}

and it worked as intended but I felt it should not be the best solution. How do you handle Ajax requests in Spring MVC, if you have such a scenario (actually, it seems to be quite usual to me)? Should I (always) use RequestMethod.PUT? (or what is the best HTTP method for Ajax in Spring?)

Is there a way to map more than one method with same HTTP method in the same controller (an obvious answer should be no)? Again, which approach do you use when you need to work with Ajax in Spring MVC? Hope you follow what I mean! It’s quite difficult for me to express as my English is at the very initial stage.

  • 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-09T09:55:59+00:00Added an answer on June 9, 2026 at 9:55 am

    There’s no such thing as best method for AJAX.

    As for what methods you should use, it depends on the architectural style. The REST paradigm and its most common practical interpretation, ROA (Resource Oriented Architecture) make certain assumptions as to the semantics of HTTP methods. It’s an increasingly popular approach and I think it’s worth reading about. Making full use of the benefits of REST would probably require you to rethink your entire app design, though. If you decide to do it this way, read up on REST, ROA and JAX-RS, the Java standard for RESTful applications. Its implementations can be integrated with Spring.

    Alternatively, you can just stick to GET and POST, as the most widely-supported methods. As for Spring itself, the reasonable way to do it would be to provide a separate bean (or perhaps a set of beans) to take care of your AJAX-based API. There will be no method “conflict” if you keep the URLs different.

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

Sidebar

Related Questions

Spring MVC allows to define handler methods with a variety of parameters which are
Spring MVC uses a DispatcherServlet to route control to an appropriate Controller. But where
I'm using Spring MVC, and I was wondering if it's possible to use methods
I'm working with Spring MVC on google app engine and even though I've gotten
My Spring MVC app is full of methods that look like this: @RequestMapping(value =
My spring MVC is not working and i am getting error resource not found.
In Spring MVC 3.0, there is a class org.springframework.validation.BindingResult which finds the form parameters.
In Spring MVC there seem to be two parallel class hierarchies, one with portlet,
I've mapped the Spring MVC dispatcher as a global front controller servlet on /*
With Spring MVC 3, when a user goes to http://localhost/myspringapp/ how do I decide

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.