Grails - 使用 g:actionSubmit 提交表单时出现错误 404
Grails - error 404 on form submit using g:actionSubmit
我是 Grails 新手,在提交表单时遇到问题。
这是 AnimaisController:
package jogoanimais
class AnimaisController {
def index() {
def animalsTreeObj = AnimaisTreeMap.list()
render(view: "show", model: [animalList: animalsTreeObj])
}
def addNode()
{
log.info "add node"
log.info params
}
}
这里是show.gsp
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<g:textField name="myField" value="${myValue}" />
<g:actionSubmit value="OK, próximo" />
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
单击提交按钮后,请求的 URL 为“http://localhost:8080/jogoAnimais/animais/addNode”,我收到 404 错误。
我也试过添加 "action" do g:actionSubmit 但在这种情况下,Grails 请求 addNode.gsp.
有人知道吗?
解决方法如下:
普惠制:
添加 g:form 的 "action" 参数和输入类型 "submit" 如下所示:
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<div>
<label for="questionToUser">Questão:</label>
<g:textField name="questionToUser" maxlength="50"/>
</div>
<input type="submit" value="Submit">
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
控制器:
正如mbaird所说,我的"addNode"方法需要return一些东西,如"render 'ok'"
我是 Grails 新手,在提交表单时遇到问题。
这是 AnimaisController:
package jogoanimais
class AnimaisController {
def index() {
def animalsTreeObj = AnimaisTreeMap.list()
render(view: "show", model: [animalList: animalsTreeObj])
}
def addNode()
{
log.info "add node"
log.info params
}
}
这里是show.gsp
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<g:textField name="myField" value="${myValue}" />
<g:actionSubmit value="OK, próximo" />
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
单击提交按钮后,请求的 URL 为“http://localhost:8080/jogoAnimais/animais/addNode”,我收到 404 错误。
我也试过添加 "action" do g:actionSubmit 但在这种情况下,Grails 请求 addNode.gsp.
有人知道吗?
解决方法如下:
普惠制:
添加 g:form 的 "action" 参数和输入类型 "submit" 如下所示:
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<div>
<label for="questionToUser">Questão:</label>
<g:textField name="questionToUser" maxlength="50"/>
</div>
<input type="submit" value="Submit">
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
控制器:
正如mbaird所说,我的"addNode"方法需要return一些东西,如"render 'ok'"