当我在groovy grails框架中提交不在数据库中的数据时出现404错误

时间:2014-07-02 06:28:00

标签: grails groovy gsp

这是我的gsp页面,当我在数据库中使用值提交它时工作正常,但是当我使用不在数据库中的某些数据查询它时失败。理想情况下它应该显示结果未找到但是它给了我一个空白页面404错误???

<%@ 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" />
<g:set var="entityName"
    value="${message(code: 'booking.label', default: 'Booking')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
    <div id="wrapper">
        <div id="page-wrapper">
            <div id="check-status" class="content scaffold-create" role="main">

                <h1 align="center">Check Booking Status</h1>
                <br> <br>
                <div class="row row-center">
                    <div class="col-lg-12">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title">
                                    <i class="fa fa-money"></i> Enter Details For Checking Booking
                                    Status
                                </h3>
                            </div>

                            <div class="panel-body">
                                <g:form action='check' ,controller='Booking'>
                                    <table align="center">

                                        <tr>
                                            <td>
                                                <div
                                                    class="fieldcontain ${hasErrors(bean: bookingInstance, field: 'bookingNo', 'error')} required">
                                                    <label for="bookingNo"> <g:message
                                                            code="booking.bookingNo.label" default="Booking No" /> <span
                                                        class="required-indicator">*</span>
                                                    </label>
                                                    <g:textField name="bookingNo" required=""
                                                        value="${params.bookingNo}" placeholder="Enter BOOKING NO" />
                                                </div> <br>
                                            </td>

                                            <td width="50%">
                                                <div
                                                    class="fieldcontain ${hasErrors(bean: bookingInstance, field: 'firstBuyerPhone', 'error')} required">
                                                    <label for="firstBuyerPhone"> <g:message
                                                            code="booking.firstBuyerPhone.label"
                                                            default="First Buyer Phone" /> <span
                                                        class="required-indicator">*</span>
                                                    </label>
                                                    <g:textField name="firstBuyerPhone" required=""
                                                        value="${params.firstBuyerPhone}"
                                                        placeholder="Enter Phone Number" />
                                                </div> <br>
                                            </td>
                                        </tr>
                                    </table>
                                    <fieldset>
                                        <g:submitButton name="check" class="btn btn-success"
                                            value="${message(code: 'default.button.check.label', default: 'Check Booking Status')}" />

                                    </fieldset>
                                </g:form>
                            </div>


                        </div>
                        <div>           
                            <g:if test ="${bookingInstance!=null}">

                                    <h3>Booking Details</h3>
                                    <table  align="left">

                                        <tr>
                                            <td><b>First Buyer Email Id </b>${bookingInstance.firstBuyerEmailId }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b>Second Buyer Email Id </b>${bookingInstance.secondBuyerEmailId }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b>Discount  </b>${bookingInstance.discount }
                                            </td>
                                        </tr>

                                        <tr>
                                            <td><b>Taxes </b>${ bookingInstance.taxes}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b>Booking Date  </b><g:formatDate format="MM/dd/yyyy"
                                                    date="${bookingInstance.bookingDate}" />

                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b>Plot No </b>${bookingInstance.home.plotNo }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b> Home Type  </b>${bookingInstance.home.homeType }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><b>Associate Name  </b><g:each  var="property" status="status"
                                                    in="${bookingInstance.associates.name}">

                                                    <g:if test="${status != 0}">
                                                    ${"," }
                                                     </g:if>

                                                    ${property}
                                                </g:each>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td><b>Payment Schedule Name  </b><g:each var="property" status="status"
                                                    in="${bookingInstance.paymentSchedules.name}">

                                                    <g:if test="${status != 0}">
                                                    ${"," }
                                                     </g:if>

                                                    ${property}

                                                </g:each>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td><b>Payment Schedule Amount </b> <g:each var="property" status="status"
                                                    in="${bookingInstance.paymentSchedules.amount}">

                                                    <g:if test="${status != 0}">
                                                    ${"," }
                                                     </g:if>

                                                    ${property}

                                                </g:each></td>
                                        </tr>

                                        <tr>
                                            <td><b>Payment Schedule DueDate </b><g:each var="property" status="status"
                                                    in="${bookingInstance.paymentSchedules.dueDate}">


                                                    <g:if test="${status != 0}">
                                                    ${"," }
                                                     </g:if>
                                                    <g:formatDate format="MM/dd/yyyy" date="${property}" />


                                                </g:each>
                                        </tr>


                                    </table>

                                </g:if>
                                <g:if test="${bookingInstance==null }">
                                Result Not Found 
                                </g:if>


                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

</body>
</html>

我在Bookingcontroller中调用的方法是

def check(){
        if(request.method == 'POST')    {
            def bookingNo=params.bookingNo as Integer
            def firstBuyerPhoneNo=params.firstBuyerPhone

            println "booking number"+bookingNo+" PhoneNumber"+firstBuyerPhoneNo
            Booking bookingInstance = null
            try {

                bookingInstance=bookingService.findByFirstBuyerPhoneAndBookingNo(firstBuyerPhoneNo,bookingNo)

            }
            catch (Exception ex){
                ex.printStackTrace();
            }

            respond bookingInstance
        }
    }


I have just no clue that what the problem is in the form or in my controller ?

0 个答案:

没有答案