用jsp和servlet开发的简单通讯录

源代码在线查看: delete.java

软件大小: 78 K
上传用户: xiaoexiao
关键词: servlet jsp 通讯
下载地址: 免注册下载 普通下载 VIP

相关代码

				package project1;
				
				import java.io.IOException;
				import java.io.PrintWriter;
				import java.sql.*;
				
				import javax.servlet.*;
				import javax.servlet.http.*;
				
				public class delete extends HttpServlet {
				    private static final String CONTENT_TYPE = "text/html; charset=GBK";
				
				    public void init(ServletConfig config) throws ServletException {
				        super.init(config);
				    }
				
				    public void service(HttpServletRequest request, 
				                        HttpServletResponse response) throws ServletException, IOException
				                                                              {response.setContentType(CONTENT_TYPE);
				        PrintWriter out = response.getWriter();
				        out.println("");
				        out.println("delete");
				        out.println("");
				         request.setCharacterEncoding("GBK");
				         //验证身份
				         HttpSession sess = request.getSession();
				         if((sess.getAttribute("token"))==null){
				             out.print("对不起,请先登录");
				             response.setHeader("Refresh","1;URL=login.jsp"); 
				         }
				         else{
				             
				                 String frd_id=request.getParameter("frd_id");
				                     String sqlString;
				                     sqlString = "delete from friends where frd_id="+frd_id;
				                   
				                     Connection conn;
				                     Statement sql;
				                try{     
				                     conn=DriverManager.getConnection("jdbc:odbc:myaddressBook");
				                     sql=conn.createStatement();
				                     sql.executeUpdate(sqlString);
				                     conn.close();
				                     out.print("朋友删除成功");
				                     response.setHeader("Refresh","1;URL=list_all");
				             }catch(SQLException e){
				                out.print(e);
				             }
				         }
				        out.println("");
				        out.close();
				    }
				}
							

相关资源