當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。