日期:2014-05-17 浏览次数:20852 次
<action name="download" class="Actions.FileActions">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="contentDisposition">attachment;filename="${fileFileName}"</param>
<param name="inputName">downloadFile</param>
<param name="bufferSize">4096</param>
</result>
<result name="input">/index.jsp</result>
</action>
public InputStream getDownloadFile() {
// System.out.println("downloadfile...");
File_UploadDaoImpl uploadDaoIpml = null;
DownloadHistoryDaoImpl historyDaoImpl = null;
conn = DBCPpool.getConnection();
uploadDaoIpml = new File_UploadDaoImpl(conn);
historyDaoImpl = new DownloadHistoryDaoImpl(conn);
File_Upload file = null;
try {
file = uploadDaoIpml.selectFileById(Integer.parseInt(id));
fileFileName = file.getFileName() + file.getType();
fileFileName = new String(fileFileName.getBytes(),"iso8859-1");
//登记下载记录
//从session中获取当前用户
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
DownloadHistory downHistory = new DownloadHistory();
downHistory.setUserName(user.getLoginName());
downHistory.setFileId(file.getId());
downHistory.setFileName(file.getFileName());
downHistory.setFileType(file.getType());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String downTime = sdf.format(new Date());
downHistory.setDownTime(downTime);
historyDaoImpl.addHistory(downHistory);
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {