1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | package com.ucit.ca.webApp.action; import java.io.InputStream; import java.sql.SQLException; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import com.ucit.ca.webApp.po.User; import com.ucit.ca.webApp.service.ICheckAppService; import com.ucit.ca.webApp.service.IDownLoadsService; import com.ucit.ca.webApp.service.Impl.DownLoadsServiceImpl; /** * 下载文件 * @author JiF * */ public class DownLoadsAction extends ActionSupport { private static final Log log = LogFactory.getLog(DownLoadsAction. class ); @Resource private IDownLoadsService downLoadsService; //下载服务层 @Resource private ICheckAppService checkAppService; //检查登陆用户对应用的权限 private String kid; // Report输出流 public InputStream resultStream; // 输出流Content Type public String contentType; // 输出流的生成的文件名 public String fileName; /** * 证书下载 * @return */ public String getP12(){ HttpServletRequest request = ServletActionContext.getRequest(); User user; try { user=checkAppService.CheckLoginUser(request); if (user== null && !user.getUid().equals(kid)){ log.error( "log24" ); addActionMessage( "log24" ); return INPUT; } resultStream=downLoadsService.getP12(kid); } catch (SQLException e) { //获取P12文件异常 log.error(e.getMessage()); addActionError(e.getMessage()); return INPUT; } catch (Exception e) { //获取帐号有异常 log.error(e.getMessage()); addActionError( "e.getMessage()" ); return INPUT; } contentType = "application/x-pkcs12" ; fileName = "attachment; filename=\"" +user.getUloginId()+ ".p12\"" ; log.info( "down p12 Success" ); return SUCCESS; } public String getKid() { return kid; } public InputStream getResultStream() { return resultStream; } public String getContentType() { return contentType; } public String getFileName() { return fileName; } public void setKid(String kid) { this .kid = kid; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!-- 下载--> < package name= "down" namespace= "/Down" extends = "global_package" > <action name= "downLoad_*" method= "{1}" class = "downLoadAction" > <result name= "success" type= "stream" > <!-- 对应contentType属性 --> <param name= "contentType" >${contentType}</param> <!--对应的InputStream的属性名 --> <param name= "inputName" >resultStream</param> <!-- 对应属性fileName,定义流输出格式 --> <param name= "contentDisposition" >${fileName}</param> <!-- 定义bufferSize,可选 --> <param name= "bufferSize" > 1024 </param> </result> <result name= "input" >/down/i_{ 1 }.jsp</result> </action> </ package > |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· .NET Core GC压缩(compact_phase)底层原理浅谈
· Winform-耗时操作导致界面渲染滞后
· Phi小模型开发教程:C#使用本地模型Phi视觉模型分析图像,实现图片分类、搜索等功能
· 语音处理 开源项目 EchoSharp