WEB开发课程设计-新闻发布系统(14)
发布时间:2021-06-06
发布时间:2021-06-06
新闻发布系统
import com.opensymphony.xwork2.ActionSupport; public class DeleteFileAction extends ActionSupport { private int id;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
@Override
public String execute() throws Exception {
UploadManager manager = new UploadManager(); String path = ServletActionContext.getRequest().getRealPath("/upload/file");
System.out.println(manager.getFileNameById(this.getId())); File file = new File(path,manager.getFileNameById(this.getId())); try{
if(manager.deleteFile(this.getId())){ file.delete();//删除磁盘上的文件
ServletActionContext.getRequest().setAttribute("state", "deleteFileSuc"); }
}catch(Exception e){ e.printStackTrace();
ServletActionContext.getRequest().setAttribute("state", "deleteFileFail");
return ERROR; }
return SUCCESS; } }
3.5 留言管理
功能:删除留言
实现:根据后台指定要删除留言的Id,在数据库中删除留言及其下级留言 public boolean deleteMessage(String id){ boolean b = false; try {
con = DBConnector.getConnection();
ps =con.prepareStatement("delete from messages where pid=?");
ps.setString(1, id); ps.executeUpdate();