Note that there are some explanatory texts on larger screens.

plurals
  1. POREST method's won't PUT or POST to the server
    text
    copied!<p>I'm trying to get some REST methods working in my Spring app but seem to be running into little success. I'm obviously missing something but I can't tell for the life of me what it would be. Here is my controller:</p> <pre><code>@Controller public class IndexController { static Logger log = Logger.getLogger(IndexController.class); @Autowired private ProvisionService provisionService; @RequestMapping(value="/home/data", method=RequestMethod.GET, headers="Accept=application/json") public @ResponseBody List&lt;Provision&gt; getData() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String username = null; if(principal instanceof UserDetails) username = ((UserDetails)principal).getUsername(); return provisionService.getAllByUser(username); } //JSON put request - doesn't work currently @RequestMapping(value="/home/data", method=RequestMethod.PUT, headers="Content-Type=application/json") @ResponseStatus(HttpStatus.NO_CONTENT) public void updateProvisions(@RequestBody List&lt;Provision&gt; provisions) { log.info("Provisions: " + provisions.toString()); } @RequestMapping(value={"/","/home"}, method=RequestMethod.GET) public void showIndex() {} } </code></pre> <p>Here is the main part of JSP that utilizes it:</p> <pre><code>&lt;sf:form id="homeForm" method="put" action="${homeData_url}"&gt;&lt;/sf:form&gt; </code></pre> <p>The form is submitted through Javascript when the user clicks on a button. Anyway, things work fine for the GET. I get Json returned with my List of objects, no problems. I then display that using Dojo and so far so good. However, when I try to return the Json with this form I'm getting a 405 - Request method 'POST' not supported error. As you can see I've got the method handler in my Controller so I'm really not sure what I'm doing wrong. I've taken those handler's out of the Spring in Action 3 book and it also resembles what some Spring docs and stuff say to do, but obviously I'm missing a key component. Anyone have any thoughts?</p> <p>I do have the <code>HiddenHttpMethodFilter</code> mapped in my web.xml which is why I'm using the Spring form tag.</p> <p>Anyway, any thoughts or help are appreciated. Thank you.</p> <p><strong>------------------UPDATE------------------</strong></p> <p>Here are the headers after I click on the button and get the 405 error, if it helps:</p> <pre><code>http://localhost:8080/NFI/home POST /NFI/home HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 DNT: 1 Connection: keep-alive Referer: http://localhost:8080/NFI/home Cookie: JSESSIONID=584AC21ADE4F214904B9E7E2370363EF Content-Type: application/x-www-form-urlencoded Content-Length: 11 HTTP/1.1 405 Method Not Allowed Server: Apache-Coyote/1.1 Allow: GET, PUT Content-Type: text/html;charset=utf-8 Content-Length: 1085 Date: Fri, 21 Oct 2011 15:39:26 GMT </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload