Spring org.apache.jasper.jaspereException:在第[24]行处理[WEB-INF/views/person.jsp]时发生异常
正在尝试从运行代码。添加功能和列表是可行的。但是更新数据会导致JSP错误。 下面是错误日志 org.apache.jasper.jaspereException:在第[24]行处理[WEB-INF/views/person.jsp]时发生异常Spring org.apache.jasper.jaspereException:在第[24]行处理[WEB-INF/views/person.jsp]时发生异常,spring,spring-mvc,jsp,Spring,Spring Mvc,Jsp,正在尝试从运行代码。添加功能和列表是可行的。但是更新数据会导致JSP错误。 下面是错误日志 org.apache.jasper.jaspereException:在第[24]行处理[WEB-INF/views/person.jsp]时发生异常 22: <form:form action="${addAction}" commandName="person"> 23: <table> 24: <c:if test
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代码
<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>
看起来您发送的是一个
对象[]
,而不是人
对象
在这里阅读更多
要解决此问题,请在向请求添加属性之前,确保传递的对象类型(Person)正确
final TypedQuery query=entityManager.createQuery(“从person-person中选择person.name”,person.class);
最终列表resultList=query.getResultList();
Person=resultList.get(0);
map.addAttribute(“person”,person);
如果这没有帮助,请发布您的后端代码
<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>
final TypedQuery<Person> query = entityManager.createQuery("SELECT person.name from Person person", Person.class);
final List<Person> resultList = query.getResultList();
Person person = resultList.get(0);
map.addAttribute("person", person);