📄 deletecomment.java
字号:
package cn.ialvin.bbs.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.ialvin.bbs.bean.Comment;
import cn.ialvin.bbs.bean.Topic;
import cn.ialvin.bbs.bean.User;
import cn.ialvin.bbs.dao.DAOFactory;
import cn.ialvin.bbs.dao.ICommentDAO;
import cn.ialvin.bbs.dao.IManagerDAO;
import cn.ialvin.bbs.dao.ITopicDAO;
import cn.ialvin.web.Servlet;
public class DeleteComment extends Servlet {
private static final long serialVersionUID = -3715588695755649239L;
public DeleteComment() { super(); }
public void destroy() { super.destroy(); }
public void doAction(
HttpServletRequest request,
HttpServletResponse response,
PrintWriter out,
DAOFactory factory)
throws ServletException, IOException, SQLException {
int id;
try {
id = this.getIParameter("id", request);
} catch (Exception e) {
this.alert("非法进入", null);
return;
}
Object o = request.getSession().getAttribute("usr");
if (o == null) {
this.alert("非法进入!", null);
return;
}
User usr = (User)o;
ICommentDAO cd = factory.getCommentDAO();
ITopicDAO td = factory.getTopicDAO();
IManagerDAO md = factory.getManagerDAO();
Comment com = cd.getComment(id);
Topic topic = td.getTopic(com.getTopic());
if (usr.isAdmin() || md.isManager(usr.getUsn(), topic.getForum())) {
cd.deleteComment(id);
this.alert("删除评论成功", out);
this.replace("../ShowTopic?id=" + topic.getId(), out);
} else {
this.alert("非法进入!", out);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -