当前位置: 首页>>代码示例>>Java>>正文


Java CommonsMultipartResolver.resolveMultipart方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsMultipartResolver.resolveMultipart方法的具体用法?Java CommonsMultipartResolver.resolveMultipart怎么用?Java CommonsMultipartResolver.resolveMultipart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.commons.CommonsMultipartResolver的用法示例。


在下文中一共展示了CommonsMultipartResolver.resolveMultipart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upload2

import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
/**
	 * 向当前运行的war中上传文件
	 * @param upPath
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalStateException
	 * @throws IOException
	 */
	@RequestMapping("/upload")
	public String upload2(HttpServletRequest request, HttpServletResponse response)
			throws IllegalStateException, IOException {
//	@RequestParam String upPath ,
		log.info("upPath:[{}][{}]", request.getParameter("upPath"), request.getAttribute("upPath"));
		String upPath = "/tpl/";
		log.info("username[{}],upPath[{}]开始上传文件", SessionUtil.getUserInfo().getMember().getAccNo(), upPath);
		String rootPath = request.getSession().getServletContext().getRealPath("/");
		log.debug("获取到项目根路径为rootPath[{}]", rootPath);
		
		
		ShiroHttpServletRequest shiroRequest = (ShiroHttpServletRequest) request;
		CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
		MultipartHttpServletRequest multipartRequest = commonsMultipartResolver.resolveMultipart((HttpServletRequest) shiroRequest.getRequest());
		
		
		Iterator<String> itr = multipartRequest.getFileNames();  
	    MultipartFile file = null; 
	    while (itr.hasNext()) {  
	    	file = multipartRequest.getFile(itr.next());
	        long pre = System.currentTimeMillis();
			if (file != null) {
				if (StringUtils.isNotBlank(file.getOriginalFilename())) {
					String fileName = StringUtil.combinationString(upPath, "/", file.getOriginalFilename());
					String path = rootPath + fileName;
					File localFile = new File(path);
					file.transferTo(localFile);
				}
			}
			long finaltime = System.currentTimeMillis();
			log.info("上传文件耗时:{}" , (finaltime - pre));
	    }
		return "file/success";
	}
 
开发者ID:ls960972314,项目名称:report,代码行数:44,代码来源:FileUpLoad.java

示例2: Request

import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
public Request(HttpServletRequest servletRequest, ApplicationInstance application) throws IOException {
	if (logger.isDebugEnabled()) {
		logger.debug("Content-Type: " + servletRequest.getContentType() + ", charset=" + servletRequest.getCharacterEncoding());
	}
	this.servletRequest = servletRequest;
	
	CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
	if (multipartResolver.isMultipart(servletRequest)) {
		MultipartHttpServletRequest mpr = multipartResolver.resolveMultipart(servletRequest);
		this.servletRequest = mpr;
		body = mpr.getFileMap();
	} else if (StringUtils.startsWithIgnoreCase(this.servletRequest.getContentType(), "application/json")) {
		byte[] bytes = IOUtils.toByteArray(this.servletRequest.getInputStream());
		String charset = this.servletRequest.getCharacterEncoding();
		if (StringUtils.isEmpty(charset)) {
			charset = application.getApplication().getCharsetEncoding();
		}
		String s = new String(bytes, charset);
		
		ObjectMapper mapper = new ObjectMapper();
		body = mapper.readValue(s, Object.class);
	}
	
	requestAttributeMap = new RequestAttributeMap(this.servletRequest);
	requestHeaderMap = new RequestHeaderMap(this.servletRequest);
	requestParameterMap = new RequestParameterMap(this.servletRequest);
}
 
开发者ID:lane-cn,项目名称:getty,代码行数:28,代码来源:Request.java

示例3: doPost

import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
    MultipartHttpServletRequest httpServletRequest = multipartResolver.resolveMultipart(request);
    Map<String, MultipartFile> map = httpServletRequest.getFileMap();
    MultipartFile multipartFile = map.values().iterator().next();
    receivedFiles.add(multipartFile.getOriginalFilename());
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:FakeArtifactPublisherServlet.java


注:本文中的org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。