import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class kustutaja extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connection=DriverManager.getConnection("jdbc:odbc:uudised","",""); PreparedStatement ps; int id=0; boolean com=false; HttpSession session = request.getSession(true); Boolean tmpLog=(Boolean)session.getAttribute("logitud"); if(!(tmpLog!=null && tmpLog.booleanValue())){ response.sendRedirect("uudisteViga"); } if (request.getParameter("id")!=null){ id=Integer.parseInt(request.getParameter("id")); }else{ response.sendRedirect("uudised"); } if (request.getParameter("comment")!=null){ com=true; ps=connection.prepareStatement("delete from comments where comid=?"); }else{ ps=connection.prepareStatement("delete from messages where id=?"); } ps.setInt(1, id); ps.executeUpdate(); if (com){ response.sendRedirect("uudisteKom?id="+request.getParameter("msgid")); }else{ ps=connection.prepareStatement("delete from comments where msgid=?"); ps.setInt(1, id); ps.executeUpdate(); response.sendRedirect("uudised"); } }catch(Exception e){ response.sendRedirect("uudised"); } } }