带有Spring Boot的Spring MVC:表单标记错误 - 期望的等号

时间:2014-05-10 22:27:26

标签: spring jsp spring-mvc

我正在尝试使用使用弹簧启动构建的应用中的标签来填充控制器提供的值的表单。但是我收到了一个错误:

org.apache.jasper.JasperException: /WEB-INF/jsp/index.jsp (line: 52, column: 102) equal symbol expected

index.jsp的相关部分:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
  <head>

    <title><spring:message code="title.main" /></title>

  </head>

  <body>
    <%@include file="include/navbar.jsp" %>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-12 col-sm-offset-0 col-md-8 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-body">
                    <form:form method="get" id="indexForm" commandName="indexForm" action="<c:url value="index_search" />" role="form">
                        <div class="row">
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label for="city_out"><spring:message code="label.index.0" /></label>
                                    <input:input type="text" class="form-control" id="city_out" path="city_out" />
                                </div>
                                <div class="form-group">
                                    <label for="city_in"><spring:message code="label.index.1" /></label>
                                    <form:input type="text" class="form-control" id="city_in" path="city_in" />
                                </div>
                                <div class="form-group">
                                    <label for="company"><spring:message code="label.index.2" /></label>
                                    <form:input type="text" class="form-control" id="company" path="company" />
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label for="date0"><spring:message code="label.index.3" /></label>
                                    <form:input type="datetime" class="form-control" placeholder="dd.MM.yyyy [HH:mm]" id="date0" path="date0" />
                                </div>
                                <div class="form-group">
                                    <label for="date1"><spring:message code="label.index.4" /></label>
                                    <form:input type="text" class="form-control" placeholder="dd.MM.yyyy [HH:mm]" id="date1" path="date1" />
                                </div>
                                <div class="form-group" align="right">
                                    <br />
                                    <button type="submit" id="search_btn" data-loading-text="Loading..." class="btn btn-primary">Search</button>
                                </div>
                            </div>
                        </div>
                    </form:form>

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

  </body>
</html>

我创建了一个匹配表单字段的类:

public class IndexForm {
    private String city_out;
    private String city_in;
    private String company;
    private String date0;
    private String date1;
// getters, setters
}

在主类中创建了一个bean(我希望如此):

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
    @Bean
    public static IndexForm indexForm() {
        return new IndexForm();
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

Controller包含此方法:

@RequestMapping("/index")
public String index(@RequestParam(value="e", required=false) List<Integer> errors, Map<String, Object> model) {
    model.put("indexForm", new IndexForm());
    if (errors != null)
        model.put("errors", errors);
    return "index";
}

我没有看到与我见过的例子有任何不同,所以如果有人指出我的错误,我会很高兴。

2 个答案:

答案 0 :(得分:1)

一些新手通过根据需要设置字段以验证字段是否填充而出错 例如在正常的HTML中 -      input type =“text”name =“name”required

在spring - form:input path =“firstName”required ....此处必需将无效,因此错误类型为“预期的等号”。

答案 1 :(得分:0)

喔。看起来,包括jsp标签在内的一个并不起作用。所以,我改变了

action="<c:url value="index_search" />" 

action="index_search" 

并且没有错误地收到我的页面。