downloadaction.java
来自「使用spring ,hibernate 框架的稽查管理系统」· Java 代码 · 共 65 行
JAVA
65 行
package com.je.ims.controller.c11;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.je.ims.util.*;
import com.je.ims.dao.*;
import com.je.ims.hibernate.FileManager;
import com.chttl.im.organization.Person;
import org.springframework.web.bind.RequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class DownloadAction implements Controller {
private FileDownloadBean filedownloadbean;
public void setFiledownloadbean(FileDownloadBean c1){
this.filedownloadbean=c1;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
HttpSession session = request.getSession();
response.setCharacterEncoding("MS950");
Person personMe = (Person) session.getAttribute("person");
if( (personMe==null) || (personMe.getUserID()== null) )
{
response.sendRedirect("../../auditsystem/login.jsp");
return null;
}
try{
Long id =new Long(RequestUtils.getRequiredStringParameter(request, "key"));
FileManager filemanager=new FileManager();
filemanager=filedownloadbean.getFilemanagedao().getFile(id);
String filename=filemanager.getFileCname()+"."+filemanager.getFileType();
System.out.println(filename);
//String filename=filemanager.getFileCname();
//java.io.File file = new java.io.File("d:" + "/upload/" + filename);
String allfileadd=new String();
String idd=String.valueOf(id);
allfileadd="d:"+"/upload/"+idd+"."+filemanager.getFileType();
System.out.println(allfileadd);
filedownloadbean.download(response,allfileadd);
return null;
}
catch(Exception e)
{
Map model = new HashMap();
model.put("errorMessage","數據錯誤!");
model.put("link",null);
return new ModelAndView("error.jsp",model);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?