我在配置彈簧MVC以在右側控制器中處理表單POST數據時遇到問題。我有一個add
行動,它將爲數據庫添加一條新記錄。彈簧進程POST數據 - 註釋正確的控制器
表單提交後,我得到404錯誤(http://localhost:8084/lyricsBase/song/submit.html
),所以我想我在路由表單提交時出錯了。
這是我的控制器代碼:
public class SongController extends MultiActionController {
[...]
@RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
public ModelAndView submit(@RequestParam("song") Song song) throws Exception {
HashMap model = new HashMap();
model.put("song", song);
// or do something better here...
return new ModelAndView("t.edit", model);
}
,這是視圖形式標籤:
<form:form method="POST" commandName="song" action="submit.html">
我的應用程序的代碼可以在github。這裏是重要的文件:the form view,controller(該類是一個多控制器,因爲我不想爲每個動作創建一個單獨的文件)和servlet configuration。
不知道它是否重要,但我使用瓷磚視圖層(和邏輯視圖名稱在tiles.xml中使用)。
此外,我不完全瞭解彈簧佈線如何工作。到現在爲止,我確定在servlet XML映射,但不知道這是否是一個好方法...
請在您的問題中添加相關的代碼片段。 – 2013-03-06 22:51:57
@KeesdeKooter添加了重要的代碼片段。 – ducin 2013-03-06 22:55:59
如果使用@RequestMapping註釋映射您的請求,則不需要將它映射到您的servlet.xml中。 – 2013-03-06 23:02:36