1.表单必须这样写:
<form name="wzBaiscBusiForm" method="post" enctype="multipart/form-data" action="">
2.Action中的处理代码
MultiPartRequestWrapper req = (MultiPartRequestWrapper) ServletActionContext.getRequest();
String attmNumber = "";
Enumeration enu = req.getFileParameterNames();
String realpath = Config.getInstance().getValue("..."); // 附件存放路径
while (enu.hasMoreElements()) { // 对每一个文件域进行遍历
String controlName = (String) enu.nextElement();
String[] fileNames = req.getFileNames(controlName);
File[] uploadFiles = req.getFiles(controlName);
for (int i = 0; i < uploadFiles.length; i++) {
// 创建文件夹,将文件保存到目录
File dir = new File(req.getRealPath("/") + realpath + "/");
if (!dir.exists())
dir.mkdir();
File uploadFile = uploadFiles[i];
File file = new File(req.getRealPath("/") + realpath + "/"
+ fileNames[i]);
byte[] data = new byte[8192];
int byteRead = -1;
FileInputStream in = new FileInputStream(uploadFile);
FileOutputStream out = new FileOutputStream(file);
while ((byteRead = in.read(data)) != -1) {
out.write(data, 0, byteRead);
out.flush();
}
out.close();
in.close();
}
分享到:
相关推荐
本代码主要应用的是jsp技术,而实现的文件上传功能,这个功能也是比较常见的,也是比较常用的,更是在网络中比较流行的。 技术为创建显示动态生成内容的Web页面提供了一个简捷而快速的方法。JSP技术的设计目的是...
ASP.NET 在WEBAPI中开发文件上传功能。以及MVC中如何调用
开发工具:eclipse+tomcat+jdk1.7 基于springMVC的文件上传功能
主要为大家详细介绍了使用fileupload实现文件上传功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
文档是直接贴出了jsp里边实现文件上传功能
ckeditor文件上传功能,附图片上传示例,java程序及返回结果。 strut配置 <param name="allowedTypes">image/bmp||image/png||image/gif||image/jpeg||image/jpg||image/pjpeg</param> ...
Flash结合PHP实现文件上传功能,程序配置说明: 1.php文件路径 upload.fla 文件中第一帧第代码第14行:urlRequest.url = "http://localhost/phpFlash/upload.php"; 此路径改为您的本地环境配置路径,注意,...
js实现文件上传功能,无需安装flash
ReactNative 实现的文件上传功能,支持任意文件上传
JSP文件上传功能,用于实现Struts上传功能
JavaWeb文件上传功能 JavaWeb文件上传功能JavaWeb文件上传功能JavaWeb文件上传功能
文件,图片上传,限定后缀名的文件上传功能
jquery实现的ajax文件上传功能 $.ajaxFileUpload ( { url:'doajaxfileupload.php', secureuri:false, fileElementId:'fileToUpload', dataType: 'json', success: function (data, ...
基于Qt实现文件上传功能:利用QTcpSocket 和QTcpServer 实现的客户端和服务端,采用Qt5.9.9编写,可以实现大文件上传至服务端的功能,详情参考博客:https://blog.csdn.net/m0_37251750/article/details/122192672
jQuery+ajax实现文件上传功能 jQuery+ajax实现文件上传功能(显示文件上传进度),供大家参考,具体内容如下 具体实现步骤 1、定义UI结构,引入bootstrap的CSS文件和jQuery文件 2、给上传按钮绑定点击事件 3、验证...
一个简单struct文件上传功能实例,很容易看懂的源代码。
smartupload组件实现文件上传功能
注意:input[type=file] 标签中的属性accept=application/msword,application/pdf 在pc上正常,但是在手机ios和android上这个文件格式限制会被忽略,所以需要在js中增加格式的判断,以及对应显示样式的设置.(我也是刚...
多文件上传组件_Flash+ASP实现多文件上传功能,免费