index.jsp中的表单部分代码
<form action="query.do" method="post">
<table>
<tr>
<td>CustomerName:</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td><input type="submit" value="Query"/></td>
<td><a href="">Add New Customer</a></td>
</tr>
</table>
</form>
servlet中的调用方法中的代码
private void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter(name);
String address = request.getParameter(address);
String phone = request.getParameter(phone); //这里的错误The local variable address may not have been initialized
/*
CriteriaCustomer cc = new CriteriaCustomer(name, address, phone);
List<Customer> customers = customerDAO.getForListWithCriteriaCustomer(cc);
request.setAttribute("customers", customers);
request.getRequestDispatcher("/index.jsp").forward(request, response);
*/
}
------解决方案--------------------
这么写能通过编译吗?应该是
String name = request.getParameter("name");
String address = request.getParameter("address");
String phone = request.getParameter("phone");