当我导航到页面时,为什么会自动调用send()函数?
我希望能够查看gsp页面,填写几个文本字段,然后通过“发送”操作调用提交
这是我的gsp文件
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<title>Contact Form</title>
</head>
<body>
<g:form name="contactForm" action = "send">
<g:render template = "contactFormFields"/>
<g:actionSubmit value = "submit" action = "send"/>
</g:form>
</body>
</html>
这是contactFormFields模板
<g:select name = 'subject' from = '${EmailService.options}' noSelection='Topic'/>
Contact Name: <g:textField name = "contact"/>
Contact Number: <g:textField name = "phone"/>
Contact Email: <g:textField name = "email"/>
Aditional Information:
<g:textArea name = "information" rows="5" cols="40"/>
EmailServiceController
class EmailServiceController {
def defaultAction = "contactService"
def send() {
sendMail(){
to "mygroovytest@gmail.com"
from params.email
subject params.subject
body params.information
}
}
}
域类
class EmailService {
static constraints = {
def options = new ArrayList()
options.push("Qestions about service")
options.push("Feedback on performed service")
options.push("Other")
options.push("Why am I doing this")
}
}
调用服务的gsp
<div class="banner">
<h1>My HVAC company</h1>
<a href = "javascript: contactPop()"> Contact me today!</a>
<a href = "services">Services</a>
<a href = "emailService">Have Me Contact You!</a>
</div>
答案 0 :(得分:1)
您的contactService
中没有EmailServiceController
操作,因此当您链接到没有操作名称的控制器时,它可能会将send()
视为默认操作。尝试添加空的contactService
操作
def contactService() { }