2013-04-22 2 views
0

plupload 플러그인에서 업로드 한 파일 이름이 null로 표시됩니다. 원본 파일 이름은 어떻게 얻을 수 있습니까? 제 실수는 어디 있는지 말해주세요.struts2 파일 이름 및 내용 유형 null, 업로드시 업로드

JSP

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%> 
<html> 
<head> 
<title>test</title> 
<sj:head compressed="false"/> 
<link rel="stylesheet" type="text/css" href="plup/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" /> 
<script type="text/javascript" src="plup/plupload.full.min.js"></script> 
<script type="text/javascript" src="plup/jquery.plupload.queue/jquery.plupload.queue.js"></script> 
<script type="text/javascript"> 
/* Convert divs to queue widgets when the DOM is ready */ 
$(function(){ 
    function plupload(){ 
     $("#uploader").pluploadQueue({ 
      // General settings 
      runtimes : 'html5,gears,browserplus,silverlight,flash,html4', 
      url : 'uploads', 
      max_file_size : '10mb', 
      unique_names : true, 
      chunk_size: '2mb', 
      // Specify what files to browse for 
      filters : [ 
       {title: "Image files", extensions: "jpg,gif,png"}, 
       {title: "Zip files", extensions: "zip"} 
      ], 
      resize: {width: 320, height: 240, quality: 90}, 

      // Flash settings 
      flash_swf_url : 'plup/Moxie.swf', 
      // Silverlight settings 
      silverlight_xap_url : 'plup/Moxie.xap', 
      multipart_params: {'user': 'admin', 'time': '2012-06-12'} 
     }); 
    } 
    plupload(); 
    $('#clear').click(function(){ 
     plupload(); 
    }); 
}); 
</script> 

</head> 

<body> 
    <div> 
     <div style="width: 750px; margin: 0px auto"> 
      <form id="formId" action="submit.action" method="post"> 
       <div id="uploader"> 
        <p>Flash, Silverlight, Gears, BrowserPlus,HTML5 .</p> 
       </div> 
       <input type="button" value="Clear" id="clear"/> 
      </form> 
     </div> 
    </div> 
</body> 

</html> 

액션

@Action(value="plupUploaduploads") 
     public String upload() throws Exception { 
       isMultipart = ServletFileUpload.isMultipartContent(getReq()); 
       System.out.println(getReq().getParameter("value")); 
       ServletContext servletContext = getReq().getServletContext(); 
       String filePath = servletContext.getRealPath("/"); 
       System.out.println(filePath); 
       System.out.println(this.file); 
       System.out.println(this.fileName); 
       System.out.println(this.contentType); 
       File theFile = new File("c:\\",this.getFileName()); 
       FileUtils.copyFile(file,theFile); 
     return SUCCESS; 
    } 

//getters and setters 

제가 지정된 인쇄 문에 따라 본체에 볼 수있다.

o_17oq47949abc11n51pg11rnah06a.jpg 
E:\Documents and Settings\Pluto\My Documents\NetBeansProjects\ShareApp\build\web\ 
c:\temp\upload__408094b5_13e30976641__7fea_00000003.tmp 
null 
null 

내 struts 구성에 문제가 있습니까? 나는 주석을 사용하고 있으므로 struts.xml 파일이 없다. 또는 파일 이름을 전송하는 plupload에 문제가 있습니다. 이름 매개 변수를 얻었을 때 실제 이름이 아닌 다른 이름 인 "o_17oq47949abc11n51pg11rnah06a.jpg"가 표시되기 때문입니다. 그렇다면 어떻게 원래 이름을 얻을 수 있습니까? 당신은 간단한 것을 작업을 수행하는 모든 플러그인을 사용하는 이유를 나는 아직도 이해가 안

감사와 관련

답변

0

이제 해결되었습니다. plupload 옵션에 unique_names : false을 설정합니다. 콘텐츠 유형 및 파일 이름은 struts 액션에서 null입니다. getParameter("name");을 사용하여 파일 이름을 검색했습니다.

1

. AJAX upload이 필요합니까?

액션 코드 :

하지 않으면, 당신은 단순히 단순히 액션으로 같은 접두사와 세 개의 변수를 선언하여, 자동 filesize 검사, filenamecontenttype 감지 기능, 동작 하나 개 이상의 파일을 업로드> <s:file /을 사용할 수 있습니다
private File fileUpload; 
private String fileUploadContentType; 
private String fileUploadFileName; 
/* getters and setters */ 

JSP 코드 :

<s:file name="fileUpload" /> 

이 그럼 당신은 파일 크기 검사, 서버 측 파일 크기 체크 (자바 스크립트, HTML5) 클라이언트 측을 수행하고 서버 측 O를 설정할 수 있습니다 다중 파트 요청 크기 (Struts.xml의 경우, 주석을 사용할 때도 있어야 함). 최종 제안으로 struts2 s:form element trims the s:url parameter in the action attribute

을 :

현재 내용을 읽을 수 있습니다 작동 뭔가를 간단하게, 그것은 확장/사용자 정의 시작합니다.

+0

나는 간단하게 s : form 및 s : file을 사용할 수 있으며 여러 파일을 처리 할 수 ​​있음을 알고 있습니다. 필요한 것은 아약스 업로드 및 단일 필드 업로드입니다. 만약 내가 struts 방식으로 여러 파일을 업로드하고 싶다면 복수 파일을 필요로합니다. 파일을 찾아보고 단일 파일 필드를 찾고 업로드 할 여러 파일을 찾고 있습니다. 희망이 무엇인지 알기를 바랍니다.Thankyou – Aadam

+0

게다가 내가 생각하는 자체 파일 이름은 plupload에 의해 변경되고있다. 아직도 나는 잘 모르겠다. – Aadam

+0

Struts2-jQuery 플러그인을 사용해 보셨습니까? http://stackoverflow.com/questions/5270288/upload-file-in-struts2-using-ajax 항상 s : 파일이 필요하지만, 단순히 jQuery를 사용하여 AJAX 호출을 perfomr로 업로드하면된다. 드래그 앤 드롭으로 업로드 할 때마다 다음과 같이 자바 스크립트를 작성해야합니다. http://html5doctor.com/drag-and-drop-to-server/ –

0

솔루션 : struts.xml에서

추가 파일 업로드의 interceoptor (< 인터셉터-REF 이름 = "파일 업로드"/>)

액션 클래스에 다음 속성을 추가합니다.

private String[] fileFileName; 

    private String[] fileContentType; 

    private File[] file;