String notice = request.getParameter("notice");
System.out.println(notice);//可以在console看到修改的数据
NoticeBean nb = new NoticeBean(); 这里没有数据, 你的notice也没有添加进实体类。
NoticeDao dao = new NoticeDao();
try {
dao.updateNotice(nb); //相当于传了空对象
response.sendRedirect("admain.jsp");
} catch (Exception e1) {
e1.printStackTrace();
}
修改数据时,页面正常跳转,但是实际数据并没有修改
小白,用的MyEclipse,jdbc链接的数据库,增删改查除了修改都可以实现。修改时,未提示代码错误,而且页面也可以正常跳转,但是数据没有修改成功,依然是之前的数据。
具体代码如下:
dao:
public void updateNotice(NoticeBean nb) {
Connection conn = DBUtil.getConnectDb();
String sql = "update gonggao set notice = ? where id =?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, nb.getNotice());
stm.setInt(2, nb.getId());
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
int id = Integer.parseInt(request .getParameter("id"));
String notice = request.getParameter("notice");
System.out.println(notice);//可以在console看到修改的数据
NoticeBean nb = new NoticeBean();
NoticeDao dao = new NoticeDao();
try {
dao.updateNotice(nb);
response.sendRedirect("admain.jsp");
} catch (Exception e1) {
e1.printStackTrace();
}
}
jsp:
<form action="UpdateNo" method="post">
<table style="position: relative; left: 50%" class="table">
<% NoticeBean nb = (NoticeBean)request.getAttribute("nb"); %>
<tbody>
<tr class="row1">
<td valign="middle" align="center">
<input type="hidden" name="id" value="<%=nb.getId() %>"/>
</td>
<td><input type="text" class="inputgri" name="notice" style="width: 800px;height: 80px;" value="<%=nb.getNotice() %>"/>
</td>
</tr>
</tbody>
</table>
<button style="width: 30%; height: 35px; position: relative; top: -20px;right:20px"type="submit" value="提交" />
提交
</form>
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
2条回答
为你推荐
- 修改数据时,页面正常跳转,但是实际数据并没有修改
- java
- tomcat
- mysql
- 2个回答
- ssh中 no result defined for action and result error
- 1个回答
- 跨进程控制SysTreeView32树状图控件的难题
- systreeview32
- 模拟
- 消息
- 跨进程
- sendmessage
- 1个回答