首页>代码>java使用JDBC连接MySQL数据库操作电子图书增删改查项目实例>/jdbc连接数据库-源码/ebookentry-JDBC/src/servlet/deleteServlet.java
package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.BookingDao;
import entity.Booking;

public class deleteServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public deleteServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		BookingDao rms=new BookingDao();
		Booking rm=new Booking();
		int id=Integer.parseInt(request.getParameter("id"));
		rm.setId(id);
		int i=rms.delete(rm);
		if(i>0){
			List<Booking> listrm=rms.findAll();
			request.getSession().setAttribute("list", listrm);
			out.print("<script>alert('删除成功!!!');location.href='index.jsp';</script>");
		}else{
			out.print("<script>alert('删除失败!!!');location.href='index.jsp';</script>");
		}
		
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
最近下载更多
y1214435276  LV9 2024年4月11日
微信网友_6906962132258816  LV7 2024年3月16日
微信网友_6829521472425984  LV5 2024年1月20日
asddwh  LV13 2023年12月26日
321170193  LV6 2023年11月12日
jiemomo  LV12 2023年10月19日
liuliuyl  LV3 2023年6月17日
哇呜呜  LV1 2023年6月13日
微信网友_6260196253601792  LV7 2022年12月16日
wwb521  LV7 2022年11月28日
最近浏览更多
赵鑫cdsaljkdfsa  LV11 2024年7月2日
liyan54188  LV2 2024年6月25日
暂无贡献等级
Dominick  LV14 2024年5月8日
一起加油  LV5 2024年4月19日
y1214435276  LV9 2024年4月11日
微信网友_6906962132258816  LV7 2024年3月16日
微信网友_6829521472425984  LV5 2024年1月20日
Kaiaahh  LV2 2024年1月4日
放鞭炮  LV1 2023年12月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友