上传代码_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 上传代码

上传代码

 2014/8/1 14:16:45  xwcueh  程序员俱乐部  我要评论(0)
  • 摘要:1.代码:@RequestMapping({"/fileUpload.htm"})publicStringfileUpload(Modelmodel,HttpServletRequestrequest,HttpServletResponseresponse,@RequestParamMultipartFileupload){StringfileType=request.getParameter("fileType");StringfileName=upload
  • 标签:上传 代码
1. 代码:
class="java" name="code">	@RequestMapping({ "/fileUpload.htm" })
	public String fileUpload(Model model, HttpServletRequest request,
			HttpServletResponse response, @RequestParam MultipartFile upload){
		String fileType = request.getParameter("fileType");
		String fileName = upload.getOriginalFilename();
		String realPath = request.getSession().getServletContext().getRealPath("/upload");
		File newFile = new File(realPath, fileName);
		try {
			FileUtils.copyInputStreamToFile(upload.getInputStream(), newFile);
			
			PrintWriter out = response.getWriter();
			out.print(newFile.getPath());
	        out.flush();
		} catch (IOException e) {
			LOGGER.error("文件上传失败",e.getMessage());
		}

		return "orderPay/check/acceptFileList";
	}

2. jsp代码:
<form id="upForm" method="post" enctype="multipart/form-data" action="${basePath}/orderPay/fileUpload.htm" >
        	<input type="file" name="upload" id="upload"/><br/>
        	<input type="hidden" id="id" name="id" />
        	<input type="hidden" id="instNo" name="instNo" />
        	[url=#]提交[/url]
        	[url=#]取消[/url]
        </form>
上一篇: 分享:APK高级保护方法解析(一) 下一篇: 没有下一篇了!
发表评论
用户名: 匿名