EASONLEELEE
2015-04-14 02:54
采纳率: 22.2%
浏览 8.2k
已采纳

jsp中提交到Servlet的表单获取的值为什么都为NULL?

------------------addProduct.jsp---------------
<form action="${pageContext.request.contextPath}/servlet/ManagerServlet?operation=addProduct" method="post"">

 <table width="80%" border="0">
商品全称:<input type="text" id="Pro_name" name="Pro_name" style="height:30px" >
商品编码:<input type="text" style="height:30px" id="Pro_code" name="Pro_code">
                 <input type="submit" value="保存"/>

</form>

--------------------------ManagerServlet-------------------
public class ManagerServlet extends HttpServlet {
private BusinessService s = new BusinessServiceImpl();

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String operation = request.getParameter("operation");
    if("addProduct".equals(operation)){
        addProduct(request, response);
    }
}
//添加产品到数据库中
private void addProduct(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    Product p = WebUtil.fillBean(request, Product.class);
    s.addProduct(p);
    System.out.println(p.getPro_name()+p.getPro_id());
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doGet(request, response);
}

}


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

10条回答 默认 最新

相关推荐 更多相似问题