无法进行弹簧表单提交

时间:2017-04-19 10:55:49

标签: spring-mvc

您好我是Spring MVC的新手,无法提交表单。

我的Jsp代码

id
Shenzhen City, Guangdong, China
Rest of Hunan, China
China
Wuxi City, Jiangsu, China
Jinshan District, Shanghai, China
JingÕan District, Shanghai, China
Yangpu District, Shanghai, China

我的控制器

<form:form method="POST"    action="save"  commandName="report">
<div id="collapseOne" class="panel-collapse collapse in"
    role="tabpanel" aria-labelledby="headingOne">
    <div class="panel-body">
        <div class="col-md-3 col-sm-12 col-xs-12 form-group" >
            <label><spring:message code="label.report.report_type"/><span class="required">*</span></label>

            <form:select id="reportTypeSelect" class="form-control" path="reportType">

                 <form:options items="${report.reportTypes}"></form:options>

             </form:select>  
            <!--  <select
                class="form-control" name="scheduleType">
                <option><spring:message code="label.report.chose_type"/></option>
                <option><spring:message code="label.report.adhoc"/></option>
                <option><spring:message code="label.report.scheduled"/></option>
            </select> -->
        </div>
        <div class="form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12">
            <spring:message code="label.report.sql_query"/></label>
            <div class="col-md-9 col-sm-9 col-xs-12">
                <form:textarea class="resizable_textarea form-control"
                    placeholder="Write Sql Queries to exceute the records ..."  name="query" path="reportQuery"></form:textarea>
            </div>
        </div>

        <div class="col-md-3 col-sm-12 col-xs-12 form-group">
            <label><spring:message code="label.report.query_name"/><span class="required">*</span></label>
             <form:input type="text" placeholder="Query Name" name="reportQueryName" path="reportType" class="form-control"></form:input>
        </div>

        <div class="col-md-3 col-sm-12 col-xs-12 form-group">
            <label><spring:message code="label.report.schedule_date"/><span class="required">*</span></label> <input
                id="eventDate"
                class="date-picker form-control col-sm-12 col-xs-12"
                required="required" type="text">
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12 form-group">
            <label><spring:message code="label.report.emailid"/><span class="required">*</span></label> <form:input
                type="text" placeholder="Maximum 4 Email Recepients" name="email" path="emails"  class="form-control"></form:input>
        </div>
        <div class="clearfix"></div>
        <div class="form-group">
            <div class="button-right">
                <!--<button type="submit" class="btn btn-primary">Save</button>-->
                <button type="submit" class="btn btn-success"> <spring:message code="label.button.save"/>
                    </button>
            </div>
        </div>
    </div>
</div>
</form:form>

1 个答案:

答案 0 :(得分:1)

你的问题在这里:

@RequestMapping(value="/reports/save",method=RequestMethod.POST)
public String updateReports(@ModelAttribute("query") String query) 

这应该是:

@RequestMapping(value="/reports/save",method=RequestMethod.POST)
public String updateReports(@ModelAttribute("report") ReportsViewBean report) 

这是在POST之后获取模型的唯一方法,然后您可以检索模型的属性值。

您不会添加模型的代码,但请确保它具有您在表单的每个path属性中放置的所有属性。