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>
</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");
}
}