|
发表于 2014-3-21 12:04:48
|
显示全部楼层
本帖最后由 song_ning_ning 于 2014-3-21 14:18 编辑
localhost 发表于 2014-3-14 09:35
thanks a lot
简要:现在功能是当点击“导出为excel工作薄”时,不再下载文档而是上传到文档服务器 点其他(导出为。。。)的时候还是下载
1.修改/UI/system/service/report/printGetFile.j文件:(如果以文件名来区别上传文档服务器还是下载 可以在下面中代码中通过reportName进行判断)
下面的代码login()是因为在这.j中取不到当前的bSessionID 而调用action时需要 所以以system登陆再注销(不影响)- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String filename = request.getParameter("filename");
- String reportName=request.getParameter("reportName");
- String outputType=request.getParameter("outputType");
- String bsessionID=null;
- if("xls".equals(outputType)){
- try{
- if(filename.indexOf("/") == -1)
- filename = System.getProperty("java.io.tmpdir") + "/" + filename;
- System.out.println(filename);
- OutputStream out = null;
- bsessionID = login();
- File reportFile = new File(filename);
- InputStream inputStream = new FileInputStream(reportFile);
- Part[] parts = new Part[5];
- parts[0] = new StringPart("process", "/demo/actions/process/invokeAction/invokeActionProcess");
- parts[1] = new StringPart("activity", "mainActivity");
- parts[2] = new StringPart("action", "upload");
- parts[3] = new StringPart("reportName", java.net.URLEncoder.encode(reportName,"utf-8"));
- InputStreamPartSource bps = new InputStreamPartSource(inputStream, "");
- parts[4] = new FilePart("file", bps);
- ActionEngine.invokeActions(parts, ActionUtils.MULTIPART_CONTENT_TYPE, null,bsessionID, "zh-cn", new StreamCallback(response));
- }finally{
- ActionEngine.logout(bsessionID);
- }
- }else{
- ReportHelper.getFile(request, response);
- }
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- this.doGet(request, response);
- }
- public String login() throws UnknownHostException {
- String businessServer = "http://127.0.0.1:8080/BusinessServer";
- String loginName = "system";
- String password = "123456";
- // 获得本地IP地址
- String localIP = java.net.InetAddress.getLocalHost().getHostAddress();
- // 初始化动作引擎
- ActionEngine.init(businessServer);
- // 登录
- String bSessionID = ActionEngine.login(loginName, ActionUtils.md5(password), localIP, null);
- // 返回bSessionID
- return bSessionID;
- }
复制代码 2.在/BIZ/demo/actions/logic/action/invokeAction.action.m中新建upload 参数俩个:String类型的reportName Object类型的file 代码如下:
Doc doc = docs.addDoc("defaultDocNameSpace"); 红色部分为 文档中心默认目录的ID
如果想要上传到文档中心其它的目录下 比如:要上传到如图的文档目录下 就写成 Doc doc = docs.addDoc("0DAB29594BB04C768FF2082F7D47DCE2"); 这个目录ID可以在sa_docnode中找到
- public static void upload(String reportName,InputStream file) throws Exception{
- FileOutputStream outputStream=null;
- try{
- File f=new File(System.getProperty("java.io.tmpdir")+"/"+ java.net.URLDecoder.decode(reportName,"utf-8"));
- outputStream=new FileOutputStream(f);
- byte[] bt = new byte[1024];
- int i = -1;
- while((i = file.read(bt)) != -1){
- outputStream.write(bt, 0, i);
- }
- outputStream.flush();
- Docs docs=new Docs();
- Doc doc = docs.addDoc("defaultDocNameSpace");
- doc.upload(f);
- docs.createVersion();
- }finally{
- outputStream.close();
- }
- }
复制代码 |
|