DeleteServlet.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

Java

  1. package com.softeem.webmail.delbox;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.sql.Connection;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.softeem.webmail.dao.DBManager;
  12. public class DeleteServlet extends HttpServlet {
  13. public void doGet(HttpServletRequest request, HttpServletResponse response)
  14. throws ServletException, IOException {
  15. doPost(request, response);
  16. }
  17. public void doPost(HttpServletRequest request, HttpServletResponse response)
  18. throws ServletException, IOException {
  19. response.setContentType("text/html;charset=UTF-8");
  20. request.setCharacterEncoding("UTF-8");
  21.         String sql = "delete from mail where id=?";
  22. String str = request.getParameter("str");
  23. String []ss = str.split(":");
  24. Connection conn = DBManager.getConnection();
  25. try {
  26. PreparedStatement ps = conn.prepareStatement(sql);
  27. for(String s:ss){
  28. int id = Integer.parseInt(s);
  29. ps.setInt(1, id);
  30. ps.execute();
  31. }
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. response.sendRedirect("DelboxServlet");
  36. }
  37. }