📄 ftpmanage.java
字号:
package com.x3408.download;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;
import com.x3408.office.Constants;
public class FTPManage extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public FTPManage() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SmartUpload mySmartUpload=null;
CommentInfo commentInfo=null;
String commentID=null;
FileInfo fileInfo=null;
String fileID=null;
String msg=null;
String action=(String)request.getParameter("action");
if("fileDel".equals(action)){
fileID=(String)request.getParameter("fileID");
String queryString="?action=allFileQuery";
if(DownLoadADO.fileDelete(fileID)){
queryString+="&msg=文件删除成功";
}else{
queryString+="&msg=文件删除失败";
}
response.sendRedirect(Constants.C_DOWNLOAD_JAVA+queryString);
}else if("commentDel".equals(action)){
commentID=(String)request.getParameter("commentID");
commentInfo=DownLoadCommentADO.commentQuery(commentID);
if(commentInfo!=null&&DownLoadCommentADO.commentDelete("commentID", commentID)){
msg="评论成功删除";
}else{
msg="评论删除失败";
}
request.getSession().setAttribute("msg", msg);
response.sendRedirect(Constants.C_DOWNLOAD_JAVA+"?action=fileQuery&fileID="+commentInfo.getFileID());
}else if("allCommentDel".equals(action)){
fileID=request.getParameter("fileID");
if(DownLoadCommentADO.commentDelete("fileID", fileID)){
msg="关于该文件的所有评论成功删除";
}else{
msg="评论删除失败";
}
request.getSession().setAttribute("msg", msg);
response.sendRedirect(Constants.C_DOWNLOAD_JAVA+"?action=fileQuery&fileID="+fileID);
}
else if (action==null){
msg="上传文件失败,请检查是否填写标题和内容介绍";
mySmartUpload=new SmartUpload();
mySmartUpload.initialize(getServletConfig(),request,response);
mySmartUpload.setMaxFileSize(Constants.UPLOADMAXSIZE);
try {
mySmartUpload.upload();
} catch (SmartUploadException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
Request smartRequest=mySmartUpload.getRequest();
File myFile=mySmartUpload.getFiles().getFile(0);
java.io.File testDir=new java.io.File(Constants.UPLOAD_PATH);
if(!testDir.exists()){
testDir.mkdir();
}
if(!myFile.isMissing()){
fileInfo=new FileInfo(myFile.getFileName(), Constants.UPLOAD_PATH,
smartRequest.getParameter("caption"), smartRequest.getParameter("introduce"));
if(DownLoadADO.fileInsert(fileInfo)){
fileID=DownLoadADO.getNeedFileID();
try {
mySmartUpload.getFiles().getFile(0).saveAs
(Constants.UPLOAD_PATH+fileID+"_"+myFile.getFileName());
msg="上传文件成功";
} catch (SmartUploadException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
System.out.print(msg);
if ("上传文件成功".equals(msg))
System.out.println(",已上传到"+Constants.UPLOAD_PATH);
request.setAttribute("msg", msg);
request.getRequestDispatcher(Constants.S_UPLOAD_JSP).forward(request, response);
}
}
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -