JiveJdon Community Forums
在线306人   首页   主题总表   培训咨询   精华   查搜   注册    登陆
首页 » 论坛 » 开源项目大家谈
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 4 回复 / 1
 发表新帖子   回复该主题贴
dalianzj

悄悄话
发表文章: 19
注册时间: 2003年02月21日 16:31
在ofbiz体系中如何实现文件下载? 2003年09月26日 10:57 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表
我用ofbiz做一个oa,需要用到文件的上传下载,上传我已经做完了,但下载始终没有实现!我用的javaBean是jspsmartupload,下载时如果是word文档或.rar文件,浏览器总会自动打开,显示乱码!而且出现getOutputStream called错误!希望高手能帮我看一下如何实现文件下载!不胜感谢!
download.jsp如下:
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.util.*, org.ofbiz.core.service.ModelService,java.sql.* " %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%!
String docName = ""; 需要下载的文件名
int docSize = 0;
Map document = new HashMap();
LinkedList docList = null;
%>
<%
try
{
List b = delegator.findAll("ProcessDoc",UtilMisc.toList("docName"));
docList = new LinkedList(b);
}catch(Exception ex){System.out.println("查找数据库是出错!");}
try
{
if(docList!=null) docSize = docList.size();
if(docSize!=0)
{
document = (Map)docList.get(docSize-1);
docName = (String)document.get("docName");
}
}catch(Exception e){
System.out.println("取值时候出错!");
System.out.println(e.getMessage());
e.printStackTrace();
}

// Initialization
mySmartUpload.initialize(pageContext);

// Download file
mySmartUpload.downloadFile("/upload/"+docName);



%>
dalianzj

悄悄话
发表文章: 19
注册时间: 2003年02月21日 16:31
Re: 在ofbiz体系中如何实现文件下载? 2003年09月26日 10:58 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.util.*, org.ofbiz.core.service.ModelService,java.sql.* " %>
<%@ page import="org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import="org.ofbiz.core.entity.*" %>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%!
String docName = ""; 需要下载的文件名
int docSize = 0;
Map document = new HashMap();
LinkedList docList = null;
%>
<%
try
{
List b = delegator.findAll("ProcessDoc",UtilMisc.toList("docName"));
docList = new LinkedList(b);
}catch(Exception ex){System.out.println("查找数据库是出错!");}
try
{
if(docList!=null) docSize = docList.size();
if(docSize!=0)
{
document = (Map)docList.get(docSize-1);
docName = (String)document.get("docName");
}
}catch(Exception e){
System.out.println("取值时候出错!");
System.out.println(e.getMessage());
e.printStackTrace();
}

// Initialization
mySmartUpload.initialize(pageContext);

// Download file
mySmartUpload.downloadFile("/upload/"+docName);



%>
dalianzj

悄悄话
发表文章: 19
注册时间: 2003年02月21日 16:31
Re: 在ofbiz体系中如何实现文件下载? 2003年09月26日 11:01 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
代码如何显示?


// 在此输入java代码
<%@ page language=
"java" import="com.jspsmart.upload.*"%>
<%@ page import=
"java.util.*, org.ofbiz.core.service.ModelService,java.sql.* " %>
<%@ page import=
"org.ofbiz.core.util.*, org.ofbiz.core.pseudotag.*" %>
<%@ page import=
"org.ofbiz.core.entity.*" %>
<meta http-equiv=
"Content-Type" content="application/msword; charset=gb2312">
<jsp:useBean id=
"delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id=
"mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%!
String docName =
""; 需要下载的文件名
int docSize = 0;
Map document = new HashMap();
LinkedList docList = null;
%>
<%
try
{
List b = delegator.findAll(
"ProcessDoc",UtilMisc.toList("docName"));
docList = new LinkedList(b);
}catch(Exception ex){System.out.println(
"查找数据库是出错!");}
try
{
if(docList!=null) docSize = docList.size();
if(docSize!=0)
{
document = (Map)docList.get(docSize-1);
docName = (String)document.get(
"docName");
}
}catch(Exception e){
System.out.println(
"取值时候出错!");
System.out.println(e.getMessage());
e.printStackTrace();
}

// Initialization
mySmartUpload.initialize(pageContext);

// Download file
mySmartUpload.downloadFile(
"/upload/"+docName);



%>
wys1978

悄悄话
发表文章: 163
注册时间: 2002年09月03日 12:28
Re: 在ofbiz体系中如何实现文件下载? 2003年09月26日 18:45 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
由于不同的servlet container在jsp的contentType和setHeader上处理不一样,所以我不推荐在jsp页面上使用download的代码。

我在ofbiz的架构上是这样处理的,upload file以后,将文件的content Type ,file path 等一些基本信息save起来,以下为Entity定义:

<entity entity-name="Attachment"
package-name=
"com.smics.pub"
title=
"Attachment Entity">
<field name=
"attachmentId" type="numeric"/>
<field name=
"attachmentType" type="id-ne"/>
<field name=
"path" type="long-varchar"/>
<field name=
"contentType" type="mid-varchar"/>
<field name=
"fileName" type="mid-varchar"/>
<field name=
"fileSize" type="numeric"/>
<field name=
"version" type="numeric"/>
<prim-key field=
"attachmentId"/>
</entity>


在request的时候,是在java里面处理,不返回jsp,一下是controller的定义:

<request-map uri=
"viewAttachment">
<security https=
"true" auth="true"/>
<event type=
"java" path="com.smics.util.attachment.DownloadEvents" invoke="download"/>
<response name=
"success" type="none"/>
</request-map>


在java代码里面利用entity的contentType和path来处理,以下是java code:

/*
* Created on 2003-8-18
*/

package com.smics.util.attachment;

/**
* @author Quake Wang
*/


import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.ofbiz.core.util.*;
import org.ofbiz.core.entity.*;

public class DownloadEvents {
public static final String module = DownloadEvents.class.getName();

public static String download(HttpServletRequest request, HttpServletResponse response) throws Exception{
//get attachment info from database
GenericDelegator delegator = (GenericDelegator) request.getAttribute(
"delegator");
String attachmentId = request.getParameter(
"attachmentId");
//TODO: NPE check

GenericValue attachment = null;
try {
attachment = delegator.findByPrimaryKeyCache(
"Attachment", UtilMisc.toMap("attachmentId", attachmentId));
} catch (GenericEntityException gee) {
Debug.logError(gee, module);
return
"error";
}
File f = new File(attachment.getString(
"path"));
FileInputStream in = new FileInputStream(f);

response.setContentType(attachment.getString(
"contentType"));
response.setHeader(
"Content-Disposition", "filename="+attachment.getString("fileName"));
response.setContentLength((int)f.length());

//fetch the file
int length = (int)f.length();
if(length != 0) {
byte[] buf = new byte[4096];
ServletOutputStream op = response.getOutputStream();
while ((in != null) && ((length = in.read(buf)) != -1)) {
op.write(buf,0, length);
}
in.close();
op.flush();
op.close();
}

//TODO: log hit
return
"success";
}
}
redlly

悄悄话
发表文章: 44
注册时间: 2003年07月31日 00:17
Re: 在ofbiz体系中如何实现文件下载? 2004年11月24日 05:04 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
在OA系统中一个最终常见的重要的功能就是公文流转,在这种应用中如果我需要传递的一个公文(例如是word文档),而这个文档要流转到各个审批者手中进行审阅并进行修改(同时要支持文档的电子签名,既保证每一个文档的修改者所作的操作都被记录,如果他修改了其他操作者的纪录也应该被记录到),这里不但涉及到文件的下载上传还要涉及到文件的修改和签名,这种功能是否能够实现?
这个主题有 4 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
正在读取,请等待...
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
 

手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com
anti spam