【发布时间】:2017-09-30 00:14:12
【问题描述】:
我有一个从 SQL 表中提取数据的下拉菜单。一切正常,我可以选择值并提交表单。但是,当我从 String 转换值时,我的 scriptlet 给出了 NULL 异常。我做错了什么?
testCars.jsp
<form method=post action=“testCars.jsp">
<div class="cell">
Select CarID
<div class="input-control select mutiple full-size">
<select id=“carID” name=“carID” onchange="listCarIDFromDatabase();”>
<option selected disabled>--SELECT--</option>
<%
ArrayList<Integer> result = carDAO.getCarID(Integer.parseInt(id));
for (int r: result){
out.println("<option value='" + r + "'>" + r + "</option>");
request.setAttribute("r", r);
}
%>
</select>
</div>
</div>
根据 AJAX 成功填充输入 returncarID onchange="listCarIDFromDatabase();
<button class="button primary" type="submit">Generate</button></form>
<input name=“returncarID” id=“returncarID”>
<%
//Scriptlet gets the value of the dropdown in next line, but when I convert to Int it is NULL
String y = request.getParameter(“returncarID”);
out.println(y); <——Prints out value here
int x = Integer.parseInt(y);
out.println(x); <———Null Exception here
%>
【问题讨论】:
-
y 的值是数字还是其他字符串?
-
在这里打印出值,这个输出是什么?
-
值打印:900056
标签: java string jsp int numberformatexception