Announcement Announcement Module
No announcement yet.
REST won't POST or PUT to server Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • REST won't POST or PUT to server

    So I'm fairly new to Spring. In the past couple of weeks I've pretty much read through Spring in Action 2, Spring in Action 3, Spring Recipes, and Spring Security. I've started building a Spring webapp and things are going pretty well. I'm now trying to implement some Json in my app and I'm encountering some issues on sending to the server that I'm hoping someone will have some idea about. I've got it working so that on the GET method I'm getting a Json object back and it's being loaded into a Dojo grid with no problems. However, when I send a PUT or POST request back I get a 405 - Request method 'POST' not supported error. I do have the HiddenHttpMethodFilter filter added into my web.xml and I am using a Spring form. Let me add my code and hopefully someone can look it over and see if I'm missing something. The thing is, I'm basically using the code right of out SiA3...

    My Controller class for the page:
    public class IndexController {
    	static Logger log = Logger.getLogger(IndexController.class);
    	private ProvisionService provisionService;
    	@RequestMapping(value="/home/data", method=RequestMethod.GET,
    	public @ResponseBody List<Provision> getData(Model model) {
    		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    		String username = null;
    		if(principal instanceof UserDetails)
    			username = ((UserDetails)principal).getUsername();
    		String list = "";
    		model.addAttribute("list", list);
    		return provisionService.getAllByUser(username);
    	//JSON put request - doesn't work currently
    	@RequestMapping(value="/home", method=RequestMethod.PUT,
    	public void updateProvisions(@RequestBody List<Provision> provisions) {"Provisions: " + provisions.toString());
    	@RequestMapping(value={"/","/home"}, method=RequestMethod.GET)
    	public void showIndex() {}
    Most of the JSP is script dealing with the Dojo grid and some empty DIVs that the Dojo grids get put into. Then there is the following:

    <sf:form method="put" id="homeForm" action="${post_url}"></sf:form>
    In Javascript when the user clicks on a specific button I submit the form. When doing this though I get the 405 error. Oh, and ${post_url} point to the path looked for by the PUT handler in the above code. So any thoughts? If I need to provide more of my code please let me know. I could really use some help and understanding on why I can't get this to work. Even the spring docs that I've read talk about doing it this way so something is obviously missing on my end. Thanks.

  • #2
    Originally posted by cardician View Post
    However, when I send a PUT or POST request back I get a 405 - Request method 'POST' not supported error.
    Hi cardician, are you sure you are receiving request method 'POST' not supporter error? I can't anything in your controller which has a POST method.


    • #3
      I'm positive that's the error I'm receiving. And that is one of the reasons why I have no idea what I'm doing wrong.


      • #4
        The code below doesn't really make sense when you're trying to send HTTP PUT request and the error you are receiving is HTTP POST error. I think this is not the form you are actually submitting.

        <sf:form method="put" id="homeForm" action="${post_url}"></sf:form