동일한 디자인의 입력 필드와 이름을 가진 여러 폼 필드 값을 업로드 된 파일과 함께 구문 분석하고 싶습니다. 자바 스크립트를 사용하여 여러 파일 업로드 필드를 생성합니다. 사용자가 파일 설명을 입력 할 수있게 해주는 텍스트 필드가 있으면 원하는만큼 필드를 연결할 수 있습니다.아파치 커먼즈를 사용하여 formfield 값을 두 번 이상 파싱
HTML 내 자바 스크립트가 작동하는 방법
<input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';"/>
<div id="moreUploads"></div>
<div id="moreUploadsLink" style="display:none;">
<a href="javascript:addFileInput();">Attach another File</a>
</div>
확인, 해당 HTML 요소
var d = document.createElement("div");
var file1 = document.createElement("input");
file1.setAttribute("type", "text");
file1.setAttribute("name", "fileName"+upload_number);
d.appendChild(file1);
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "attachment"+upload_number);
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
를 만들기위한 자바 스크립트 : http://jsfiddle.net/8k926/90/
을 내 파일 업로드 서블릿은 디버깅 시도 첫 번째 생성 된 값만 구문 분석 중이므로 자바 스크립트에서 생성 된 다음 생성 된 필드를 구문 분석하지 않습니다.
내 파일 업로드 서블릿
if(item.isFormField())
{
String name = item.getFieldName();
if(name != null)
{
if(name.equals("fileName"))
{
fileName = item.getString();
}
else if(name.equals("main"))
{
main = item.getString();
}
else if(name.equals("sub"))
{
sub=item.getString();
}
else if(name.equals("filetype"))
{
filetype=item.getString();
}
}
}else{
String file1=item.getFieldName();
String file2=item.getName();
filen=file2;
ocation = File.separator+"home"+File.separator+"adapco"+File.separator+"Desktop"+ File.separator +"output"+ File.separator +main+File.separator+sub+File.separator+filen;
uploadFile = new File(location);
//code for connecting and inserting the form field values into the database.
}
디버거는 하나의 파일을 업로드 한 후 종료됩니다.
덕분에 같은 카운터를 작성, 난 그냥 문자열 이름 = item.getFieldName()를 선언하여 문제를 해결; 위의 경우 (item.isFormField()) 을 제거하고 자바 스크립트에서 upload_number를 제거하면 파일 이름을 fileName (기본값)에서 null로 표시 할 fileName2 (다음 반복)로 변경하는 파일을 첨부 할 때마다 upload_number가 항상 증가합니다. 이전 입력 양식 필드 만 구문 분석하십시오. – ksa
@ksa : 잘 듣고 싶습니다. –