Package org.springframework.web.multipart

Examples of org.springframework.web.multipart.MultipartHttpServletRequest


  @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  @ResponseBody
  public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
    AjaxJson j = new AjaxJson();
   
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
      MultipartFile file = entity.getValue();// 获取上传文件对象
      ImportParams params = new ImportParams();
      params.setTitleRows(2);
      params.setSecondTitleRows(2);
View Full Code Here


  @RequestMapping(params = "upload")
  @ResponseBody
    public AjaxJson upload(HttpServletRequest request, String documentTitle, HttpServletResponse response) {
    AjaxJson j = new AjaxJson();
   
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
      MultipartFile file = entity.getValue();// 获取上传文件对象
      try {
        jeecgBlobDataService.saveObj(documentTitle, file);
        j.setMsg("文件导入成功!");
View Full Code Here

  @RequestMapping(params = "saveDoc")
  @ResponseBody
    public AjaxJson saveDoc(WebOfficeEntity webOffice, HttpServletRequest request, HttpServletResponse response) {
    AjaxJson j = new AjaxJson();
   
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
      MultipartFile file = entity.getValue();// 获取上传文件对象
      try {
        webOfficeService.saveObj(webOffice, file);
        j.setMsg("文件导入成功!");
View Full Code Here

      updateEntitie(object);
    }
    else {
    try {
      uploadFile.getMultipartRequest().setCharacterEncoding("UTF-8");
      MultipartHttpServletRequest multipartRequest = uploadFile.getMultipartRequest();
      ReflectHelper reflectHelper = new ReflectHelper(uploadFile.getObject());
      String uploadbasepath = uploadFile.getBasePath();// 文件上传根目录
      if (uploadbasepath == null) {
        uploadbasepath = ResourceUtil.getConfigByName("uploadpath");
      }
      Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
      // 文件数据库保存路径
      String path = uploadbasepath + "/";// 文件保存在硬盘的相对路径
      String realPath = uploadFile.getMultipartRequest().getSession().getServletContext().getRealPath("/") + "/" + path;// 文件的硬盘真实路径
      File file = new File(realPath);
      if (!file.exists()) {
View Full Code Here

  private UploadResponse doUpload(HttpServletRequest request, String typeStr,
      String currentFolderStr, Boolean mark) throws Exception {
    ResourceType type = ResourceType.getDefaultResourceType(typeStr);
    try {
      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      // We upload just one file at the same time
      MultipartFile uplFile = multipartRequest.getFileMap().entrySet()
          .iterator().next().getValue();
      // Some browsers transfer the entire source path not just the
      // filename
      String filename = FilenameUtils.getName(uplFile
          .getOriginalFilename());
View Full Code Here

  public AjxpAnswer execute(FileDriver driver, HttpServletRequest request) {
    if (!(request instanceof MultipartHttpServletRequest)) {
      throw new AjxpDriverException(
          "Cann only deal with MultipartHttpServletRequest");
    }
    MultipartHttpServletRequest mpr = (MultipartHttpServletRequest) request;
    String dir = mpr.getParameter("dir");
    String fileName = mpr.getParameter("Filename");

    InputStream in = null;
    OutputStream out = null;
    File file = null;
    try {
      MultipartFile mpfile = mpr.getFile("Filedata");
      in = mpfile.getInputStream();
      file = driver.getFile(dir, fileName);
      out = new FileOutputStream(file);
      IOUtils.copy(in, out);
    } catch (IOException e) {
View Full Code Here

      return convertToType(val, clazz);
    }
  }
 
  public static ComplexData convertToComplexData(HttpServletRequest request, String name) {
    MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
    MultipartFile file = mRequest.getFile(name);
    if (file != null && file.getSize() > 0) {
      try {
        return new ComplexData(file.getOriginalFilename(), file.getInputStream());
      }
      catch (IOException e) {
View Full Code Here

    request.addUserRole("role1");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ComplexWebApplicationContext.MockMultipartResolver multipartResolver =
        (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext()
            .getBean("multipartResolver");
    MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
    complexDispatcherServlet.service(multipartRequest, response);
    multipartResolver.cleanupMultipart(multipartRequest);
    assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE));
    assertNotNull(request.getAttribute("cleanedUp"));
  }
View Full Code Here

    request.addUserRole("role1");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ComplexWebApplicationContext.MockMultipartResolver multipartResolver =
        (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext()
            .getBean("multipartResolver");
    MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
    complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response);
    multipartResolver.cleanupMultipart(multipartRequest);
    assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE));
    assertNotNull(request.getAttribute("cleanedUp"));
  }
View Full Code Here

      NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {

    HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
    assertIsMultipartRequest(servletRequest);

    MultipartHttpServletRequest multipartRequest =
      WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

    String partName = getPartName(parameter);
    Object arg;

    if (MultipartFile.class.equals(parameter.getParameterType())) {
      Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
      arg = multipartRequest.getFile(partName);
    }
    else if (isMultipartFileCollection(parameter)) {
      Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
      arg = multipartRequest.getFiles(partName);
    }
    else if (isMultipartFileArray(parameter)) {
      Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
      List<MultipartFile> files = multipartRequest.getFiles(partName);
      arg = files.toArray(new MultipartFile[files.size()]);
    }
    else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
      assertIsMultipartRequest(servletRequest);
      arg = servletRequest.getPart(partName);
View Full Code Here

TOP

Related Classes of org.springframework.web.multipart.MultipartHttpServletRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.