我正在尝试从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>
为什么我无法删除部门名称?
答案 0 :(得分:0)
如果我错了,请纠正我,但异常与deleteDepartment代码无关,而是与addDepartment.jsp页面有关,那么你如何将这两者连接在一起呢?
同样来自numberFormatException,似乎java试图将departmentName值转换为Integer。这当然没有意义,因为我想你会在这个领域喂一个字符串。
我不完全确定问题来自您共享的代码,但我感觉某种混合选择departmentId或departnmentName选择“部门”,以便删除它。因此,从String值转换为抛出异常的数值。