rounda 2017-04-24 08:37 采纳率: 0%
浏览 2526

jsp页面中的表单数据在Servlet中取出来全为null

jsp页面中都是输入了数据的,可是Servlet中获取的数据每一个都为null
jsp:

    <form action="../addnews" method="post" enctype="multipart/form-data">
      <p>
        <label> 主题 </label>
        <select name="natid">
        <option>选择</option>
          <c:forEach items="${themelist}" var="t">
            <option value="${t.themeId}">${t.themeName}</option>
          </c:forEach>
        </select>
      </p>
      <p>
        <label> 标题 </label>
        <input name="natitle" type="text" class="opt_input" />
      </p>
      <p>
        <label> 作者 </label>
        <input name="naauthor" type="text" class="opt_input" value="${ui.username}" />
      </p>
      <p>
        <label> 内容 </label>
        <textarea name="nacontent" cols="70" rows="10"></textarea>
        &nbsp;&nbsp;
      </p>
      <input name="action" type="hidden" value="addnews"/>
      <input type="submit" value="提交" class="opt_sub" />
      <input type="reset" value="重置" class="opt_sub" />
    </form>

    servlet:
        public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        String i = request.getParameter("natid");
        int id = 1;
        if (i != null) {
            id = Integer.parseInt(i);
        }
        String title = request.getParameter("natitle");
        String author = request.getParameter("naauthor");
        String content = request.getParameter("nacontent");
        NewsDao ttd = new NewsDaoImpl();
        News ni = new News(id, title, author, content, new Date());
        int b = ttd.addNews(ni);
        if (b > 0) {
            response.sendRedirect("first");
        }
    }

  • 写回答

5条回答 默认 最新

  • engchina 2017-04-24 08:53
    关注

    可以把jsp页面代码分享出来吗?

    你可以用debug模式,看看request里面都有什么。

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程