java - NumberFormatException: For input string: "xxxx" -
i'm trying display data on jsp page using jstl. i'm getting error numberformatexception: input string: "expense_id"
.
code
list expense = entitymanager .getentitymanager() .createnativequery( "select e.expense_id, format(e.expense_amount,2) expense_amount, date_format(e.expense_date, \"%y-%m-%d\") expense_date, e.expense_desc, e.payment_method, g.expense_group_name, c.company_name, e.comment 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 request request.setattribute("expenses", expense); // redirect expense_list.jsp util.redirect(request, response, "/web-inf/expense/expense_list.jsp");
jsp code
<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>
error
exception :org.apache.jasper.jasperexception: exception occurred processing jsp page /web-inf/expense/expense_list.jsp @ 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:
how can solve ?
you trying cast "expense_id" number. since "expense_id" string, cast throw numberformatexception. common problem doing (in pseudocode):
print "expense_id";
when want print variable value of expense_id. should instead (again pseudocode) like:
print expense_id; // no quotes
on line 47, try changing:
<td style="width: 5%;"><a href="expense_manage?expense_id=${expense.expense_id}">
to:
<td style="width: 5%;"><a href="expense_manage?expense_id="+${expense.expense_id}>
Comments
Post a Comment