⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 download.java

📁 辅助办公系统,具有发布公告、站内邮箱、日程安排、日志查看等功能
💻 JAVA
字号:
package com.x3408.download;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;
import com.x3408.employees.UserADO;
import com.x3408.employees.UserInfo;
import com.x3408.office.Constants;
import com.x3408.office.ReadByMultipage;

public class DownLoad extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public DownLoad() {
		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{
		String action=request.getParameter("action");
		Vector fileList=null;
		FileInfo fileInfo=null;
		String msg="无效的操作";
		String fileID=null;
		String filePath=null;
		SmartUpload mySmartUpload=null;
		String showPage=null;
		ReadByMultipage readByMultipage=null;
		if("allFileQuery".equals(action)){
			fileList=DownLoadADO.allFileQuery();
			if(fileList==null||fileList.size()<1){
				msg="没有可下载的文件";
				request.setAttribute("msg",msg);
				request.getRequestDispatcher(Constants.S_DOWNLOADMORE_JSP);
			}else{
				showPage=request.getParameter("showPage");
				readByMultipage=new ReadByMultipage(fileList,13);
				fileList=readByMultipage.getPage(showPage);
				request.setAttribute("recordCount", readByMultipage.getRecordCount());
				request.setAttribute("pageCount", readByMultipage.getPageCount());
				request.setAttribute("showPage", readByMultipage.getShowPage());
				request.setAttribute("fileList", fileList);
				request.getRequestDispatcher(Constants.S_DOWNLOADMORE_JSP).forward(request, response);
			}
			return;
		}else if("fileQuery".equals(action)){
			fileID=request.getParameter("fileID");
			fileInfo=DownLoadADO.fileQuery(fileID);
			Vector commentList=DownLoadCommentADO.allCommentQuery(fileID);
			if(fileInfo==null){
				msg="该文件不存在";
			}else{
				request.setAttribute("commentList", commentList);
				request.setAttribute("fileInfo", fileInfo);
			}
			request.getRequestDispatcher(Constants.S_DOWNLOAD_JSP).forward(request, response);
			return;
		}else if("downLoad".equals(action)){
			fileID=request.getParameter("fileID");
			if(fileID!=null&&!"".equals(fileID)){
				fileInfo=DownLoadADO.fileQuery(fileID);
				if(fileInfo!=null){
					mySmartUpload=new SmartUpload();
					mySmartUpload.initialize(getServletConfig(),request,response);
					mySmartUpload.setContentDisposition(null);
					filePath=fileInfo.getUpLoadPath().trim()+fileInfo.getFileID()+"_"+fileInfo.getName().trim();
					try {
						mySmartUpload.downloadFile(filePath,null,new String(fileInfo.getName().getBytes("GBK"),"iso-8859-1"));
						System.out.println(filePath);
						return;
					} catch (SmartUploadException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
				msg="指定的下载文件在服务器上可能不存在!";
				request.setAttribute("msg", msg);
				request.setAttribute("action", "fileQuery");
				request.getRequestDispatcher(Constants.S_DOWNLOAD_JAVA).forward(request, response);
				return;
		}else if("commentPub".equals(action)){
			CommentInfo commentInfo=null;
			HttpSession session=request.getSession();
			UserInfo userInfo=UserADO.userQuery((String)session.getAttribute("employeeID"));
			commentInfo=new CommentInfo(request.getParameter("fileID"),request.getParameter("comment"),userInfo.getName());
			if(DownLoadCommentADO.commentInsert(commentInfo)){
				msg="评论成功发布";
			}else{
				msg="请填写评论内容";
			}
			request.setAttribute("msg",msg);
			request.getRequestDispatcher(Constants.S_DOWNLOAD_JAVA+"?action=fileQuery").forward(request, response);
		}
	}

	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -