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里面都有什么。

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)