你既然选择struts框架就不要用smartupload组件了。代码大概是这样的:
import java.util.*;
import org.apache.struts.upload.FormFile;
//大字段上传
public void blobUpload(DBAccess dba,FormFile file) throws ObjectException{
try{
InputStream stream = file.getInputStream();
ResultSet rs=null; if(file.getFileSize()>0){ //有内容
byte[] bytes=file.getFileData();
dba.prepareStatement(SQL_INSERT_BLOB_UPLOAD);
if(strInsertReturnValue!=null){
dba.setString(1,strInsertReturnValue);
rs=dba.executeQuery();
if(rs.next()){ //有返回结果
oracle.sql.BLOB blob=((oracle.jdbc.OracleResultSet)rs).getBLOB("M_FILE");
OutputStream outStream = blob.getBinaryOutputStream();
outStream.write(bytes); //写入大字段
outStream.flush();
}
}else{
throw new ObjectException("上传大字段时没有取得m_id的值!");
}
}
}catch(Exception ex){
ex.printStackTrace();
throw new ObjectException(ex.getMessage());
}
} //大字段 下载
public void blobDownload(DBAccess dba,String m_id,HttpServletResponse response) throws ObjectException{
try{
dba.prepareStatement(SQL_PROCESS_BLOB_DOWNLOAD);
dba.clearParameters();
dba.setString(1,m_id);
ResultSet rs=dba.executeQuery(); if(rs.next()){
InputStream inStream=rs.getBinaryStream("M_FILE");
String fileType=rs.getString("M_FILETYPE");
response.setContentType(fileType);
byte[] b=new byte[1024];
int len;
while((len=inStream.read(b))>0){
response.getOutputStream().write(b,0,len);
}
response.getOutputStream().flush();
response.getOutputStream().close();
}
}catch(Exception ex){
ex.printStackTrace();
throw new ObjectException("大字段 下载时出错");
}
}
import java.util.*;
import org.apache.struts.upload.FormFile;
//大字段上传
public void blobUpload(DBAccess dba,FormFile file) throws ObjectException{
try{
InputStream stream = file.getInputStream();
ResultSet rs=null; if(file.getFileSize()>0){ //有内容
byte[] bytes=file.getFileData();
dba.prepareStatement(SQL_INSERT_BLOB_UPLOAD);
if(strInsertReturnValue!=null){
dba.setString(1,strInsertReturnValue);
rs=dba.executeQuery();
if(rs.next()){ //有返回结果
oracle.sql.BLOB blob=((oracle.jdbc.OracleResultSet)rs).getBLOB("M_FILE");
OutputStream outStream = blob.getBinaryOutputStream();
outStream.write(bytes); //写入大字段
outStream.flush();
}
}else{
throw new ObjectException("上传大字段时没有取得m_id的值!");
}
}
}catch(Exception ex){
ex.printStackTrace();
throw new ObjectException(ex.getMessage());
}
} //大字段 下载
public void blobDownload(DBAccess dba,String m_id,HttpServletResponse response) throws ObjectException{
try{
dba.prepareStatement(SQL_PROCESS_BLOB_DOWNLOAD);
dba.clearParameters();
dba.setString(1,m_id);
ResultSet rs=dba.executeQuery(); if(rs.next()){
InputStream inStream=rs.getBinaryStream("M_FILE");
String fileType=rs.getString("M_FILETYPE");
response.setContentType(fileType);
byte[] b=new byte[1024];
int len;
while((len=inStream.read(b))>0){
response.getOutputStream().write(b,0,len);
}
response.getOutputStream().flush();
response.getOutputStream().close();
}
}catch(Exception ex){
ex.printStackTrace();
throw new ObjectException("大字段 下载时出错");
}
}
解决方案 »
- display tag 分页问题,在线等
- JSF取hibernate多表值
- form提交到邮箱
- [300分]求struts2,hibernate,spring,ajax结合的项目下载(最好能运行)!
- 各位帮忙.HIBERNATE深入欠出第一个例子我竟然搞不定....我发多点分
- 紧急!!紧急!!
- 请问什么时候该使用静态变量呢?
- 算讨论也算请教的问题:各位大侠你们在用struts什么时候用jstl,一般你们用jstl代替struts的什么标签?谢谢
- 已有现成的XML文件及DTD,如何将其存入数据库及如何从数据库中再转换成XML?
- 哪位大哥知道JBUILD7的教程下载啊?小弟先谢过了
- xmlDocument对象对应的xml格式内容可以输入到字符串中?
- 运行struts程序时遇到的异常
SmartUpload mySmartUpload = new SmartUpload();
mySmartUpload.initialize(getServlet().getServletConfig(),httpServletRequest,httpServletResponse);
mySmartUpload.upload();