DeleteServlet.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
- package com.softeem.webmail.delbox;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.softeem.webmail.dao.DBManager;
- public class DeleteServlet extends HttpServlet {
-
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doPost(request, response);
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- request.setCharacterEncoding("UTF-8");
- String sql = "delete from mail where id=?";
- String str = request.getParameter("str");
- String []ss = str.split(":");
- Connection conn = DBManager.getConnection();
- try {
- PreparedStatement ps = conn.prepareStatement(sql);
- for(String s:ss){
- int id = Integer.parseInt(s);
- ps.setInt(1, id);
- ps.execute();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- response.sendRedirect("DelboxServlet");
- }
- }