我试图使用jstl在jsp页面上显示数据。但我收到的错误为NumberFormatException: For input string: "expense_id"
。
代码
List expense = entityManager
.getEntityManager()
.createNativeQuery(
"SELECT e.expense_id, format(e.expense_amount,2) as expense_amount, DATE_FORMAT(e.expense_date, \"%Y-%m-%d\") as expense_date, e.expense_desc, e.payment_method, g.expense_group_name, c.company_name, e.comment FROM wd_expense e "
+ "join wd_expense_group g on e.expense_group_id = g.expense_group_id "
+ "left join wd_company c on e.company_id = c.company_id")
.getResultList();
// set to request
request.setAttribute("expenses", expense);
// redirect to expense_list.jsp
util.redirect(request, response, "/WEB-INF/expense/expense_list.jsp");
JSP代码
<tbody>
<c:forEach items="${requestScope.expenses}" var="expense">
<tr>
<td style="width: 5%;"><a
href="expense_manage?expense_id=${expense.expense_id}"
class="btn btn-outline btn-primary">Edit</a>
</td>
<td>${expense.expense_desc}</td>
<td class="text-right">${expense.expense_amount}</td>
<td>${expense.expense_group_name}</td>
<td>${expense.comment}</td>
<td style="width: 10%;">
<button type="button"
onclick="ConfirmDelete('id=${expense.expense_id}','removeExpense')"
class="btn btn-outline btn-danger">Delete</button>
</td>
</tr>
</c:forEach>
</tbody>
错误
Exception :org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/expense/expense_list.jsp at line 47
44: <c:forEach items="${requestScope.expenses}" var="expense">
45: <tr>
46: <td style="width: 5%;"><a
47: href="expense_manage?expense_id=${expense.expense_id}"
48: class="btn btn-outline btn-primary">Edit</a>
49: </td>
50: <td>${expense.expense_desc}</td>
Stacktrace:
我该如何解决这个问题?
答案 0 :(得分:0)
您正在尝试将“expense_id”转换为数字。由于“expense_id”是一个String,因此该强制转换将抛出NumberFormatException。最常见的问题是(伪代码):
print "expense_id";
当您确实要打印expense_id的变量值时。这应该(再次伪代码)看起来像:
print expense_id; // No quotes
在第47行,尝试更改:
<td style="width: 5%;"><a href="expense_manage?expense_id=${expense.expense_id}">
为:
<td style="width: 5%;"><a href="expense_manage?expense_id="+${expense.expense_id}>