我有一个表单,我希望使用JQuery验证器插件进行验证。 在使用普通jsp跟踪示例之后,我在添加Spring标记后出现此错误。 这是我的JSP:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script
src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<link rel="stylesheet" type="text/css" href="resources/css/styles.css">
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Employees</title>
</head>
<body>
<br>
<div class="container">
<h3>Persons List</h3>
<table class="table table-hover table-striped">
<tr>
<th>User Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Role</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<c:forEach items="${listPersons}" var="employee">
<tr>
<td>${employee.userName}</td>
<td>${employee.firstName}</td>
<td>${employee.lastName}</td>
<td>${employee.phoneNumber}</td>
<td>${employee.role}</td>
<td><a href="<c:url value='/edit/${employee}' />">Edit</a></td>
<td><a href="<c:url value='/remove/${employee}' />">Delete</a></td>
</tr>
</c:forEach>
</table>
</div>
<!-- addition form -->
<div class="container" id="additionDiv">
<h2>Create Employee</h2>
<%-- <sf:form method="post" class="form-horizontal"
action="persistEmployee" modelAttribute="employee"> --%>
<sf:form method="post" class="form-horizontal"
modelAttribute="employee" id="additionForm">
<div class="form-group">
<sf:label class="control-label col-sm-2" for="uname"
path="userName">User Name:</sf:label>
<div class="col-sm-10">
<sf:input class="form-control" id="uname" path="userName" name="uname" minlength="4" type="text" required />
</div>
</div>
<div class="form-group">
<sf:label class="control-label col-sm-2" for="fname"
path="firstName">First Name:</sf:label>
<div class="col-sm-10">
<sf:input class="form-control" id="fname" path="firstName" name="fname" type="text" required />
</div>
</div>
<div class="form-group">
<sf:label class="control-label col-sm-2" for="lname" path="lastName">Last Name:</sf:label>
<div class="col-sm-10">
<sf:input class="form-control" id="lname" path="lastName" name="lname" type="text" required />
</div>
</div>
<div class="form-group">
<sf:label class="control-label col-sm-2" for="pnumber"
path="phoneNumber">Phone Number</sf:label>
<div class="col-sm-10">
<sf:input class="form-control" id="pnumber" path="phoneNumber" name="pnumber" minlength="7" type="digit" required />
</div>
</div>
<div class="form-group">
<sf:label class="control-label col-sm-2" for="role" path="role">Role</sf:label>
<div class="col-sm-10">
<sf:select path="role" multiple="multiple" class="form-control"
id="sel1">
<sf:option value="CONSULTANT"></sf:option>
<sf:option value="MANAGER"></sf:option>
<sf:option value="ADMIN"></sf:option>
</sf:select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</sf:form>
</div>
<!-- end addition form -->
<div class="container">
<button type="button" class="btn btn-primary" id="add-button">+</button>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
$("#add-button").click(function() {
$("#additionDiv").fadeIn("slow");
});
});
</script>
<script type="text/javascript">
$("#addition-form").validate();
</script>
<script>
$(document).ready(function() {
$("#addition-form").submit(function() {
alert("form submitted");
});
});
</script>
</html>
以下是我得到的例外情况,我不知道等号应该在哪里。
Sep 15, 2016 4:38:25 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/employees.jsp (line: 69, column: 111) equal symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:91)
at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:218)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:163)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:154)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1231)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1455)
at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1668)
at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:996)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1271)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1455)
at org.apache.jasper.compiler.Parser.parse(Parser.java:139)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1246)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1029)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:973)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
我认为,这可能是因为minlength,type和required属性。他们不在顶级域名中。
In [56]: df = pd.DataFrame(data=np.random.rand(5,5), columns=list('ABCDE'))
In [57]: df
Out[57]:
A B C D E
0 0.229201 0.145442 0.214964 0.205609 0.182592
1 0.709232 0.714943 0.983360 0.635155 0.949378
2 0.741204 0.532559 0.646229 0.649971 0.686386
3 0.073047 0.382106 0.121190 0.721732 0.146408
4 0.904605 0.115031 0.377635 0.377796 0.005747
In [58]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 5 columns):
A 5 non-null float64
B 5 non-null float64
C 5 non-null float64
D 5 non-null float64
E 5 non-null float64
dtypes: float64(5)
memory usage: 280.0 bytes ## <- check here!
您可以在此处查看TLD文档:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-form-tld.html
答案 1 :(得分:0)
Spring 期望每个属性都有一个值。由于 required
是一个布尔属性,所以只需要它的存在,所以你可以给它任何值。按照惯例,这个值通常是属性本身的名称。
<sf:input class="form-control" id="uname"
path="userName" name="uname" minlength="4" type="text"
required="required"/>