servlet用的baseservlet继承,反射获取url地址中的method的地址
@WebServlet("/orders")
public class OrderServlet extends BaseServlet{
// 3.增加配送通知单
public void addOrder(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// 测试是否调用此方法
System.out.println("进入addOrder()");
// 获取来自providerManage.jsp中id为fm的form表单传过来的数据,用来新增配送通知单.
String cidStr = req.getParameter("cid");
String username = req.getParameter("username");
String telephone = req.getParameter("telephone");
String address = req.getParameter("address");
String name = req.getParameter("name");
//测试数据接收是否成功
System.out.println("cid : "+cidStr);
System.out.println("username : "+username);
System.out.println("address : "+address);
System.out.println("telephone : "+telephone);
// 把有些参数转换成int类,因为这些参数在数据库中是int类型
int cid = Integer.parseInt(cidStr);
OrderService orderService = new OrderService();
orderService.addOrder(username, username, address, telephone, cid);
// 获取该用户通知单,再次发送至页面
OrderService service = new OrderService();
List orderList = service.findAllOrdersByCid(cid);
req.setAttribute("orderList", orderList);
System.out.println("orderList : "+orderList);
req.getRequestDispatcher("customer_orderlist.jsp").forward(req, resp);
System.out.println("addOrder结束");
}
jsp页面中的表单发送至该servlet,但是控制台打印始终显示为空