📄 delete.java
字号:
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("<html>");
out.println("<head><title>delete</title></head>");
out.println("<body>");
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("</body></html>");
out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -