啓用HTTP POST請求我使用Spring啓動,這裏的行家依賴在春季啓動
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
對於網頁,我把文件放在src /主/資源/靜態的。在那裏我有我的html文件,js庫(angular,jquery)和css文件。
我試圖與角的HTTP請求POST(我也有做工精細的GET請求),但我得到這個
POST http://localhost:8080/xxxx/12/addEntry 405 (Method Not Allowed)
在響應頭
HTTP/1.1 405 Method Not Allowed
Server: Apache-Coyote/1.1
X-Application-Context: application
Allow: HEAD, GET
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 09 Jul 2014 13:04:05 GMT
我意識到在Response中,allow不具有POST方法。
控制器
@RequestMapping(value = "/xxxx/{uid}/addEntry", method = RequestMethod.POST)
@ResponseBody
public String createEntry(@PathVariable String uid, @RequestBody String form) {
System.out.println(form);
return "index.html";
}
你確定Spring看到控制器嗎?該控制器的其他方法是否工作? – axtavt
@axtavt謝謝你的回答。 GET請求正在工作。 – agusgambina
如果您嘗試刪除'@RequestBody字符串表單',該怎麼辦? – axtavt