【发布时间】:2019-11-03 13:32:29
【问题描述】:
尝试从https://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial 运行代码。添加功能并列出作品。但更新数据会导致 JSP 错误。 下面是错误日志 org.apache.jasper.JasperException:在第 [24] 行处理 [WEB-INF/views/person.jsp] 时发生异常
22: <form:form action="${addAction}" commandName="person">
23: <table>
24: <c:if test="${!empty person.name}">
25: <tr>
26: <td>
27: <form:label path="id">
Root Cause
java.lang.NumberFormatException: For input string: "name"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
我在 JSP 方面没有太多经验。所以无法确定特定点,尝试了许多解决方案,并认为似乎是在将输入传递给字段名称。
我的 SQL 表名为 Person,如下所示
id int(11) PRIMARY Key auto_increment
name varchar(20)
country varchar(20)
以下是我的表单的完整 JSP 代码。
<form:form action="${addAction}" commandName="person">
<table>
<c:if test="${!empty person.name}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="name">
<spring:message text="Name"/>
</form:label>
</td>
<td>
<form:input path="name" />
</td>
</tr>
<tr>
<td>
<form:label path="country">
<spring:message text="Country"/>
</form:label>
</td>
<td>
<form:input path="country" />
</td>
</tr>
<tr>
<td colspan="2">
<c:if test="${!empty person.name}">
<input type="submit"
value="<spring:message text="Edit Person"/>" />
</c:if>
<c:if test="${empty person.name}">
<input type="submit"
value="<spring:message text="Add Person"/>" />
</c:if>
</td>
</tr>
【问题讨论】:
标签: spring spring-mvc jsp