我在声明int dept_id = Integer.parseInt(request.getParameter("dept_id"));
时遇到问题它总是得到java.lang.NumberFormatException:null。但是int emp_id的第一个声明它正在工作,但是对于dept_id它总是得到null值。
这是我的Servlet
public UserController() {
super();
udao = new UserDao();
ddao = new DepartmentDao();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward="";
String action = request.getParameter("action");
forward = INSERT_OR_EDIT;
int emp_id = Integer.parseInt(request.getParameter("emp_id"));
int dept_id = Integer.parseInt(request.getParameter("dept_id"));
User user = udao.GetUser(emp_id);
User user2 = ddao.GetHub(dept_id);
request.setAttribute("user", user);
request.setAttribute("user2", user2);
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
JSP
<fieldset>
<legend id="myLegend">User</legend>
<!-- <label for="emp_id">
Employee ID :
</label> -->
<input type="text" readonly="readonly" name="emp_id" style="display:none"
value="<c:out value="${user.emp_id}" />" />
<label for="serial_number">Serial Number :</label>
<input type="text" name="serial_number" placeholder="
value="<c:out value="${user.serial_number}" />" /><br /><br />
<!-- <label for="dept_id">
Department ID :
</label> -->
<input type="text" readonly="readonly" name="emp_id" style="display:none"
value="<c:out value="${user2.dept_id}" />" />
<label>Hub :</label>
<input type="text" name="department_name"
value="<c:out value="${user2.dept_name}" />" /><br /><br />
</fieldset>
答案 0 :(得分:1)
dept_id的名称是emp_id。它应该看起来像:
<input type="text" readonly="readonly" name="dept_id" style="display:none"
value="<c:out value="${user2.dept_id}" />" />
我想你只是忽略了这个!