uploadfy 怎么实现多文件上传

uploadfy 怎么实现多文件上传,第1张

在Jsp页面中编写Script代码实现上传事件的描述,必须要注意其中的路径问题,uploader(springmvc controller处理的位置),其他两个路径为uploadify文件的存放路径(这个可以到官网下载)

uploadify下载下来的文件的存放路径

在Jsp页面中编写页面的具体布置

实现页面如下

在controller目录中创建类对jsp页面中的请求进行处理,由于代码比较多,所以截图分两部分,最后面给出具体的代码文字

/**

* 处理文件上传

* @param response

* @param request

* @return

* @throws IOException

*/

@RequestMapping(value="/uploadFile",method=RequestMethod.POST)

public String upload(HttpServletResponse response,HttpServletRequest request) throws IOException{

String responseStr=""

MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request

Map<String, MultipartFile>fileMap = multipartRequest.getFileMap()

//String savePath = this.getServletConfig().getServletContext().getRealPath("")

//savePath = savePath + "/uploads/"

// 文件保存路径 ctxPath本地路径

String ctxPath=request.getSession().getServletContext().getRealPath("/")+File.separator+"uploadFiles"

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM")

String ymd = sdf.format(new Date())

ctxPath += File.separator + ymd + File.separator

System.out.println("ctxpath="+ctxPath)

// 创建文件夹

File file = new File(ctxPath)

if (!file.exists()) {

file.mkdirs()

}

String fileName = null

for (Map.Entry<String, MultipartFile>entity : fileMap.entrySet()) {

// 上传文件

MultipartFile mf = entity.getValue()

fileName = mf.getOriginalFilename()//获取原文件名

System.out.println("filename="+fileName)

File uploadFile = new File(ctxPath + fileName)

try {

FileCopyUtils.copy(mf.getBytes(), uploadFile)

responseStr="上传成功"

} catch (IOException e) {

responseStr="上传失败"

e.printStackTrace()

}

}

return responseStr

}

打开VS2013,选择文件->新建->项目。

选择web应用程序,然后重命名为【UploadifyDemo】

选中项目右键->添加->web窗体,重命名为【Upload】

给【Upload.aspx】页面添加js和插件的引用。

给【Upload.aspx】页面添加上传文件js代码。

给【Upload.aspx】页面上传文件js添加【onUploadSuccess】属性,将英文提示改成中文“上传成功”。

给【Upload.aspx】页面添加HTML代码

选中项目右键->添加->新建项,然后找到一般处理程序,重命名为【UploadFile】。

在【UploadFile】添加后台上传文件的代码。

将【Upload.aspx】设为起始页后,按住ctrl+F5,就可以查看到结果了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11495733.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存