OAF 中下载使用XML Publisher下载PDF附件
2024-08-24 19:56:11
OAF doesn't readily expose the Controller Servlet's HttpRequest and HttpResponse objects so you need to extract it from the OAPageContext object via:
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
Once you get the response object you could already manipulate its OutputStream.
public void downloadFile(OAPageContext pageContext) { HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse(); File fileToDownload = this.createFile(); String fileType = getMimeType("txt");
response.setContentType(fileType);
response.setContentLength((int) fileToDownload.length());
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileToDownload.getName() + "\""); InputStream in = null;
ServletOutputStream outs = null; try { outs = response.getOutputStream();
in = new BufferedInputStream(new FileInputStream(fileToDownload));
int ch; while ((ch = in.read()) != -1) {
outs.write(ch);
} } catch (IOException e) { // TODO
e.printStackTrace(); } finally { try { outs.flush();
outs.close(); if (in != null) {
in.close();
} } catch (Exception e) { e.printStackTrace(); } } }
参考资料:
Integrate XML Publisher and OA Framework
Downloading Files in OAF (需翻墙)
最新文章
- 网站为什么要做SEO
- linux grep 查找字符串
- mysql中的字符串类型数据索引优化
- LSB最低有效位隐写入门
- jfinal框架教程-学习笔记(二)
- VMware Workstation pro 12下载以及序列号
- sql server 2005中使用with实现递归
- 关于jdbc Oracle数据库连接的URL错误
- 《第一行代码》学习笔记14-UI(3)
- ActiveMQ的运用
- react-native自定义TextInput光标颜色
- Docker容器中安装vim
- 我发起了一个 ILBC 的 子项目 ILBC Studio
- BeanFactory和FactoryBean的区别
- 基于spring boot 2.x的websocket示例
- 获取当前页面url
- WinForm(WPF) splash screen demo with C#
- Oracle 12c 用户创建、角色、权限
- spring-security(2)
- 【转】WireShark 过滤规则