记录下最近接触的用struct上传文件的方法。
符号表:<input type="file" id="fhb" name="binfile" style="cursor:pointer;" onchange="fileChange(this,'fhb');"/>
bin文件:<input type="file" id="bin" name="binfile" style="cursor:pointer;" onchange="fileChange(this,'bin');"/>
补丁文件:<input type="file" id="bdwj1" name="upload" style="cursor:pointer;" onchange="fileChange(this,'bdwj1');"/>
public class UploadMoreAction extends ActionSupport {
private static final int NUM = 8192;
// 补丁文件
private List<String> uploads;
private List<String> fileNames;
private List<String> uploadContentTypes;
//bin和符号表
private List<String> binfiles;
private List<String> binfileFileNames;
private List<String> binfileContentTypes;
public void uploadFile() {
if (this.getUpload() != null) {
int i = 0;
for (; i < this.getUpload().size(); i++) {
InputStream is = new FileInputStream((String) this
.getUpload().get(i));
OutputStream os = new FileOutputStream("D:\\test"
+ this.getFileNames().get(i));
byte buffer[] = new byte[NUM];
int count = 0;
while ((count = is.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
os.close();
is.close();
}
}
}
public void uploadBINSTFile() {
if (this.getBinfile() != null) {
int i = 0;
for (; i < this.getBinfile().size(); i++) {
InputStream is = new FileInputStream((String) this
.getBinfile().get(i));
OutputStream os = new FileOutputStream("D:\\test"
+ this.getBinfileFileName().get(i));
byte buffer[] = new byte[NUM];
int count = 0;
while ((count = is.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
os.close();
is.close();
}
}
}
public List<String> getUploadFileName() {
return fileNames;
}
public void setUploadFileName(List<String> fileNames) {
this.fileNames = fileNames;
}
public List<String> getUpload() {
return uploads;
}
public void setUpload(List<String> uploads) {
this.uploads = uploads;
}
public void setUploadContentType(List<String> contentTypes) {
this.uploadContentTypes = contentTypes;
}
public List<String> getUploadContentType() {
return this.uploadContentTypes;
}
public List<String> getFileNames() {
return fileNames;
}
public void setFileNames(List<String> fileNames) {
this.fileNames = fileNames;
}
public List<String> getBinfile() {
return binfiles;
}
public void setBinfile(List<String> binfiles) {
this.binfiles = binfiles;
}
public List<String> getBinfileFileName() {
return binfileFileNames;
}
public void setBinfileFileName(List<String> binfileFileNames) {
this.binfileFileNames = binfileFileNames;
}
public List<String> getBinfileContentType() {
return binfileContentTypes;
}
public void setBinfileContentType(List<String> binfileContentTypes) {
this.binfileContentTypes = binfileContentTypes;
}
}
<action name="upload_*" class="com.UploadMoreAction" method="{1}">
<interceptor-ref name="fileUpload">
<!-- 配置允许上传的文件类型,多个用","分隔 -->
<param name="allowedTypes">
<!--image/bmp,image/png,image/gif,image/jpeg,image/jpg-->
</param>
<!-- 配置允许上传的文件大小,单位字节-->
<param name="maximumSize">5000000000000000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result name="success">success.jsp</result>
</action>
- 为了明了其中蹊跷,debug跟了下其中的值
- 补丁文件上传了名为test.txt, test2.txt的文本文件
- 符号表和bin文件上传了名为st.txt, bin.txt的文本文件
字段 |
值 |
uploads |
[\tmp\upload__1fea43f6_133af286d4d__8000_00000012.tmp, \tmp\upload__1fea43f6_133af286d4d__8000_00000013.tmp] |
fileNames |
[test.txt, test2.txt] |
uploadContentTypes |
[text/plain, text/plain] |
|
|
binfiles |
[\tmp\upload__1fea43f6_133af286d4d__8000_00000010.tmp, \tmp\upload__1fea43f6_133af286d4d__8000_00000011.tmp] |
binfileFileNames |
[st.txt, bin.txt] |
binfileContentTypes |
[text/plain, text/plain] |
分享到:
相关推荐
editor(通用所有文本编辑器) struts2图片上传问题解决办法
解决Struts2上传时候使用UTF-8的冲突问题: * 重新包装了JakartaMultiPartRequest提供Chartset的设置方法。 * 可以通过配置方式对MultiPartRequest中的内容进行编码设定,请在Struts.xml中配置添加struts.multipart...
struts 文件上传 Struts实现文件上传
STRUTS框架的上传DEMO,解决上传后文件名中文乱码问题! 软件为MYECLIPS直接导出,使用方法:解压后直接导入到MYECLIPS就可使用!
这个bug是由Struts2上传文件后return SUCCESS后报的错误: java.lang.AbstractMethodError: be.telio.mediastore.ui.upload.GarryMultiPartRequest.cleanUp()V ...可以完美解决此类struts2的出错问题!
解决struts组件上传附件速度很慢的问题
struts2实现文件上传。解决中文url和中文文件名乱码问题
参考了phantomes的专栏,解决了其中的FileItem调用问题。 struts2真正实现上传下载完整源代码。 包含lib jar包
很受网络上庞杂的Struts2上传下载的误导,很多没有解决中文乱码问题,本例实现了Struts2批量上传与下载,中文乱码问题完美解决,供大家参考!
struts2,fckeditor解决上传图片冲突
struts2文件上传技术,希望能解决你的困扰!
如题,本项目是一个简单的解决关于Struts1.2上传下载问题的Demo。 希望对需要的你有所帮助。
Struts2升级到2.5.30,问题解决及过程记录, 文章详见:https://blog.csdn.net/sinat_36743893/article/details/124582101
描述struts2的上传,解决乱码及中文国际化
今天主要分享开源框架Struts2文件上传实例过程,并且笔者将带着大家解决出现的一系列乱码问题,本文章中的重要部分将用特殊颜色标识,斜体表示不确定内容。笔者建议读者先快速阅读一遍本文,下载应具备的工具,再...
之前,为中文文件名出现乱码在google上搜索是大量资源,说的很好,但都未能通过验证。此次认真阅读,上机调试终于通过。
下载word文档和代码,你就一定能够解决此问题。 解决Struts2上传文件后文件大小变大
基于struts2 的文件上传与下载源码,解决中文文件名。
该实例解决了kindeditor编辑器与struts2"上传错误"的问题,能够直接运行!
Struts2文件 上传 下载 解决: a标签中文乱码,无法下载问题 tomcat下载格式变换问题,如下载apk,下载下来的则是zip