HTTP 状态 500 - 在第 21 行处理 JSP 页 /WEB-INF/views/addDepartment.jsp 时发生异常
HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/views/addDepartment.jsp at line 21
我正在尝试从我的 spring mvc 应用程序的 addDepartment.jsp 页面中的数据库中删除一个部门。当我尝试删除
时确实收到此错误
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/addDepartment.jsp at line 21
18: </tr>
19: <tr>
20: <td><form:label path="departmentName">Department Name:</form:label></td>
21: <td><form:input path="departmentName" value="${department.departmentName}"/></td>
22: </tr>
23:
24: <tr>
这是 addDepartment.jsp 文件的第 21 行
21: <td><form:input path="departmentName" value="${department.departmentName}"/></td>
这是处理删除功能的视图的控制器
@RequestMapping(value = "/deleteDepartment", method = RequestMethod.GET)
public ModelAndView deleteCategory(@ModelAttribute("command") Department department,
BindingResult result) {
departmentService.deleteDepartment(department.getDepartmentId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("department", departmentService.getDepartments());
return new ModelAndView("addDepartment", model);
}
这是错误的根本原因堆栈跟踪
java.lang.NumberFormatException: For input string: "departmentName"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:580)
java.lang.Integer.parseInt(Integer.java:615)
这是处理从 addDepartment.jsp 文件中删除的代码的视图
<c:forEach items="${departments}" var="department">
<tr>
<td><c:out value="${department.departmentId}"/></td>
<td><c:out value="${department.departmentName}"/></td>
<td align="center"><a href="editDepartment?departmentId=${department.departmentId}">Edit</a> | <a href="deleteDepartment?departmentId=${department.departmentId}">Delete</a></td>
</tr>
</c:forEach>
为什么我无法删除部门名称?
如果我错了请纠正我,但异常与 deleteDepartment 代码无关,而是与 addDepartment.jsp 页面有关,那么你是如何将这两者联系在一起的?
另外,从 numberFormatException 来看,在我看来,java 似乎正在尝试将 departmentName 值转换为整数。这当然没有意义,因为我想您将向该字段输入一个字符串。
我不完全确定问题出在您共享的代码中,但我感觉有些混淆了按 departmentId 或 departnmentName 选择 "department" 以便删除它。因此,从 String 值到抛出异常的数字值的转换发生了。
我正在尝试从我的 spring mvc 应用程序的 addDepartment.jsp 页面中的数据库中删除一个部门。当我尝试删除
时确实收到此错误org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/addDepartment.jsp at line 21
18: </tr>
19: <tr>
20: <td><form:label path="departmentName">Department Name:</form:label></td>
21: <td><form:input path="departmentName" value="${department.departmentName}"/></td>
22: </tr>
23:
24: <tr>
这是 addDepartment.jsp 文件的第 21 行
21: <td><form:input path="departmentName" value="${department.departmentName}"/></td>
这是处理删除功能的视图的控制器
@RequestMapping(value = "/deleteDepartment", method = RequestMethod.GET)
public ModelAndView deleteCategory(@ModelAttribute("command") Department department,
BindingResult result) {
departmentService.deleteDepartment(department.getDepartmentId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("department", departmentService.getDepartments());
return new ModelAndView("addDepartment", model);
}
这是错误的根本原因堆栈跟踪
java.lang.NumberFormatException: For input string: "departmentName"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:580)
java.lang.Integer.parseInt(Integer.java:615)
这是处理从 addDepartment.jsp 文件中删除的代码的视图
<c:forEach items="${departments}" var="department">
<tr>
<td><c:out value="${department.departmentId}"/></td>
<td><c:out value="${department.departmentName}"/></td>
<td align="center"><a href="editDepartment?departmentId=${department.departmentId}">Edit</a> | <a href="deleteDepartment?departmentId=${department.departmentId}">Delete</a></td>
</tr>
</c:forEach>
为什么我无法删除部门名称?
如果我错了请纠正我,但异常与 deleteDepartment 代码无关,而是与 addDepartment.jsp 页面有关,那么你是如何将这两者联系在一起的?
另外,从 numberFormatException 来看,在我看来,java 似乎正在尝试将 departmentName 值转换为整数。这当然没有意义,因为我想您将向该字段输入一个字符串。
我不完全确定问题出在您共享的代码中,但我感觉有些混淆了按 departmentId 或 departnmentName 选择 "department" 以便删除它。因此,从 String 值到抛出异常的数字值的转换发生了。