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

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条回答

  • 虚心的小子 2015-04-14 03:26
    关注

    明白我的意思没,检查你的bean。肯定有字段是form中没有的。你现在的赋值方法,要求必须一一对应

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误