看看这个贴子,有相关的讨论。希望能解决你的问题
http://community.csdn.net/Expert/topic/3896/3896720.xml?temp=.2206232
http://community.csdn.net/Expert/topic/3896/3896720.xml?temp=.2206232
解决方案 »
- jquery中addTab,在tab中只能是网页吗?
- request得到的乱码问题!!急!!
- 求IIS支持Tomcat的插件
- google google
- jsp提交表单的中文显示?
- 唉,还是jsp乱码
- 急求天气预报代码?
- 高分求救,如何在Linux下配置Jsp的运行环境呢???
- 怎么给我的控件初始化,并将它显示出来?
- 关于PreparedStatement的setObject的问题
- 求:struts 标签<html:form action="/arg/wareHouseProductOutAction" method="POST" >内是否能包含name属性?
- 如何在非servelt的类中得到javax.servlet.http.HttpServletRequest
jsp页:
<html:form action"" method="post" styleId="" enctype="multipart/form-data">
<html:file property="file" />
Action:
上传:
String filePath = servlet.getServletContext().getRealPath("/upload");
File uploadDir = new File(filePath);
//Creat upload folder
if (!uploadDir.isDirectory()) {
uploadDir.mkdir();
} FormFile file = mActionForm.getFile();
//Check File Size
if (file.getFileSize() > 10 * 1024 * 1024) {
throw new Exception("61006");
} if (file == null) {
return actionMapping.findForward("page_showFileObjectUpload");
}
String fName = file.getFileName(); long size = file.getFileSize();
//Upload File
InputStream streamIn = file.getInputStream();
OutputStream streamOut = new FileOutputStream(destFileName + "/" +
file.getFileName());
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ( (bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
streamOut.write(buffer, 0, bytesRead);
}
streamOut.close();
streamIn.close();下载:
String tempPath = servlet.getServletContext().getRealPath("/upload"); //Creat a GUId
String GUId = new ForGuid().toString();
String GUIdPath;
if (tempPath.endsWith(eConst.STR_DELIMITER_BACKLASH)) {
GUIdPath = tempPath + GUId;
}
else {
GUIdPath = tempPath + "/" + GUId;
} //Download Attachment To Temp Directory
proId = meSession.geteFile().download(id, GUIdPath, session.getAttribute("kGPassword").toString()); //Check Process Is Whether Finish
checkprocess(proId); //Decompression And Get File Path
String strArray[] = getFilePath(GUIdPath);
String fPath = strArray[0];
String fName = strArray[1]; String fileName = fName; InputStream inStream = new FileInputStream(fPath); response.reset();
response.setContentType("application/octet-stream; charset=GBK");
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); byte[] b = new byte[50];
int len;
while ( (len = inStream.read(b)) > 0) {
response.getOutputStream().write(b, 0, len);
}
response.getOutputStream().close();
inStream.close();我得这个程序还有压缩和解压缩
你根据自己的改改吧