2012-07-11 46 views
0

試圖在Spring/Hibernate中做一個非常簡單的表單。它應該添加一個條目到數據庫中。這是基於一個爲我工作的例子,所以奇怪的是我會得到這個錯誤。但是它就是這樣啊。表單提交時「HTTP狀態405 - 請求方法'不支持POST'

下面是與窗體頁:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 

<html> 
<head><title>Add Owned Game</title></head> 
<body> 
<h1>Add Owned Game</h1> 

<br /> 
<br /> 
<c:url var="saveGameeUrl" value="/games/save.html" /> 
<form:form modelAttribute="game" method="POST" action="${saveGameUrl}"> 
    <form:label path="title">Game Title:</form:label> 
    <form:input path="title" /> 
    <br /> 
    <input type="submit" value="Add Game" /> 
</form:form> 


</body> 
</html> 

而這裏的相關負責人方法:

@RequestMapping(value = "/save", method = RequestMethod.POST) 
public ModelAndView saveGame(@ModelAttribute("game") Game game, 
     BindingResult result) { 
    gameService.addOwnedGame(game); 
    return new ModelAndView("redirect:/games/owned.html"); 
} 

如果你需要看別的,讓我知道。

+0

你看過服務器日誌嗎? – PhD 2012-07-11 23:30:59

+0

服務器日誌中沒有任何內容。 – lashiel 2012-07-11 23:32:22

回答

2

它看起來像你張貼到HTML頁面(應該是靜態的),而不是/路徑到控制器的/保存頁面。另外,這是一個錯字嗎? c:url被命名爲saveGameeUrl有兩個Es,而該動作只有一個在遊戲上。

<c:url var="saveGameeUrl" value="/games/save.html" /> 
<form:form modelAttribute="game" method="POST" action="${saveGameUrl}"> 
+0

男孩哦,男孩,不是我的臉頰紅色。我認爲我已經修正了這一點。這解決了它! – lashiel 2012-07-11 23:44:14

+0

沒問題。這不會是第一次有人在代碼審查中敲響頭:)。 – Wulfram 2012-07-11 23:50:24

相關問題