我正在學習如何使用Grails,遇到了我不明白何時應該提交簡單表單提交的情況。Grails操作適用於GET請求,返回404 POST請求
我創建了一個名爲'add'的控制器(有一個AddController.groovy源文件和一個合適的add/index.gsp視圖),並定義了一個非常稀疏的'process'動作,它目前呈現少量的HTML以驗證該操作正在被調用。 (不出意外)http://localhost:8080/frontend/add/process/。
我想向流程操作提交一個非常簡單的表單,作爲與某些現有Java庫集成的第一步。
向http://localhost:8080/frontend/add/process/發送GET請求會導致調用進程動作,瀏覽器顯示相關的簡單HTML內容。
向http://localhost:8080/frontend/add/process/發送POST請求會返回HTTP 404錯誤。
我很欣賞我錯過了一些基本的補充,我的應用程序,使上述行動與GET和POST請求。我默認假設請求類型無關緊要。
如果我可以發送一個POST請求到適當的動作,並有一些標記只是爲了演示事情正在工作,我會很高興在這個階段。
我錯過了什麼從根本上解決了難題?
控制器/前端/ AddController.groovy:
package frontend
class AddController {
def index = { }
def process = {
render "<h1>process action being performed</h1>"
}
}
視圖/添加/ index.gsp中
<html>
<head>
<title>Test View for index action</title>
<meta name="layout" content="main" />
</head>
<body>
<g:form controller="add" action="process">
<label for="title">Title:</label>
<g:textField name="title" id="title" />
<label for="content">Content:</label>
<g:textArea name="content" id="content" />
<g:actionSubmit value="Add" />
</g:form>
</body>
</html>
保存一天......最後得到了這個答案花兩小時後。 – codesnooker 2014-04-30 10:03:50