-
大小: 36.25MB文件類(lèi)型: .rar金幣: 1下載: 0 次發(fā)布日期: 2023-07-11
- 語(yǔ)言: 其他
- 標(biāo)簽: springmvc??webuploader??
資源簡(jiǎn)介
親自編寫(xiě),但也是多方面參考。編寫(xiě)過(guò)程:簡(jiǎn)單明了,附有圖片說(shuō)明。加載即可實(shí)現(xiàn)功能。如有不明之處,請(qǐng)致電QQ7784187
代碼片段和文件信息
package?com.webuploader.controller;
import?java.io.File;
import?java.io.IOException;
import?java.text.SimpleDateFormat;
import?java.util.Date;
import?java.util.Iterator;
import?java.util.Random;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.RequestMapping;
import?org.springframework.web.multipart.MultipartFile;
import?org.springframework.web.multipart.MultipartHttpServletRequest;
import?org.springframework.web.multipart.commons.CommonsMultipartResolver;
import?org.springframework.web.servlet.ModelAndView;
@Controller
public?class?UploadController?{
@RequestMapping(“index“)
public?String?index(){
return?“index“;
}
@RequestMapping(“/touploader“)
????public?ModelAndView?touploader(){
ModelAndView?model=new?ModelAndView();
model.setViewName(“uploader“);
return?model;
}
@RequestMapping(“/upload“)
public?void?addFile(HttpServletRequest?request
HttpServletResponse?response)
throws?IllegalStateException?IOException?{
String?uid=request.getParameter(“uid“);//獲取uid
String?pid=request.getParameter(“pid“);//獲取jsp?id參數(shù)
System.out.println(uid);
System.out.println(pid);
CommonsMultipartResolver?multipartResolver?=?new?CommonsMultipartResolver(
request.getSession().getServletContext());
if?(multipartResolver.isMultipart(request))?{
MultipartHttpServletRequest?multiRequest?=?(MultipartHttpServletRequest)?request;
Iterator?iter?=?multiRequest.getFileNames();
while?(iter.hasNext())?{
//?int?pre?=?(int)?System.currentTimeMillis();//開(kāi)始時(shí)時(shí)間
MultipartFile?file?=?multiRequest.getFile(iter.next());
if?(file?!=?null)?{
String?myFileName?=?file.getOriginalFilename();
if?(myFileName.trim()?!=?““)?{
String?fileName?=?file.getOriginalFilename();
String?fileExt?=?fileName.substring(
fileName.lastIndexOf(“.“)?+?1).toLowerCase();
SimpleDateFormat?df?=?new?SimpleDateFormat(
“yyyyMMddHHmmss“);
String?newFileName?=?df.format(new?Date());
String?fileNames?=?newFileName
+?new?Random().nextInt(1000)?+?“.“?+?fileExt;
?String?path?=?“d:/“?+?fileNames;//上傳路徑
//?String?path?=
//?request.getSession().getServletContext()
//?.getRealPath(“/resources/contractImgs“)
//?+?“/“?+?fileNames;
File?localFile?=?new?File(path);
if?(!localFile.exists())?{//?如果文件夾不存在,自動(dòng)創(chuàng)建
localFile.mkdirs();
}
file.transferTo(localFile);
}
}
}
}
}
}
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????643??2017-05-02?16:58??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.classpath
?????文件????????916??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.project
?????文件????????564??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\.jsdtscope
?????文件????????364??2017-05-02?16:56??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\org.eclipse.jdt.core.prefs
?????文件????????584??2017-05-02?16:58??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\org.eclipse.wst.common.component
?????文件????????305??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????49??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件???????1743??2017-05-02?17:36??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\config\springmvc.xm
?????文件???????2492??2017-05-02?17:43??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\src\com\webuploader\controller\WebuploaderController.java
?????文件???????2710??2017-05-02?17:42??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\js\upload.js
?????文件?????????39??2017-05-02?16:57??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\me
?????文件??????86709??2017-05-02?10:59??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\tool\jQuery\jquery-3.1.1.min.js
?????文件?????143099??2017-05-02?14:48??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\tool\webuploader\Uploader.swf
?????文件????????515??2017-05-02?14:48??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\tool\webuploader\webuploader.css
?????文件?????280424??2017-05-02?14:48??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\tool\webuploader\webuploader.js
?????文件???????3949??2017-05-02?17:43??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\classes\com\webuploader\controller\WebuploaderController.class
?????文件???????1743??2017-05-02?17:36??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\classes\springmvc.xm
?????文件????2029794??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\ant-1.9.6.jar
?????文件??????18392??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\ant-launcher-1.9.6.jar
?????文件???????4467??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\aopalliance-1.0.jar
?????文件??????53468??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\asm-5.1.jar
?????文件?????610790??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\c3p0-0.9.1.2.jar
?????文件?????299725??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\cglib-3.2.4.jar
?????文件?????326877??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\com.springsource.net.sf.cglib-2.2.0.jar
?????文件?????173139??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\com.springsource.net.sf.cglib-sources-2.2.0.jar
?????文件???????4615??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\com.springsource.org.aopalliance-1.0.0.jar
?????文件??????21188??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\com.springsource.org.aopalliance-sources-1.0.0.jar
?????文件????1642154??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
?????文件?????160519??2017-05-02?10:31??圖片上傳簡(jiǎn)單實(shí)現(xiàn)\webUploader_v1.0\WebRoot\WEB-INF\lib\commons-dbcp-1.4.jar
............此處省略196個(gè)文件信息
評(píng)論
共有 條評(píng)論