0
아마도 중복 된 질문이 될 수 있습니다. 인터넷에서 비슷한 게시물을 읽었지만 jsp에서 서블릿으로 입력 값을 보낼 수 없습니다. 파일을 업로드 할 수 있지만 입력 값을 보내야합니다. 서블릿 :jsp의 multipart/form-data에서 입력 값을 서블릿에 전달하는 방법은 무엇입니까?
try {
FileItemIterator iterator = upload.getItemIterator(req);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream in = item.openStream();
if (item.isFormField()) {
out.println("Got a form field: " + item.getFieldName());
} else {
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
out.println("--------------");
out.println("fileName = " + fileName);
out.println("Kind = " + fileNameWithOutExt);
out.println("field name = " + fieldName);
out.println("contentType = " + contentType);
String fileContents = null;
try {
fileContents = IOUtils.toString(in);
out.println("lenght: " + fileContents.length());
String[] content = fileContents.split("\n");
String[] property = content[0].split(",");
out.println("lunghezza " + property.length);
for (String propr : property) {
out.println("prop: " + propr);
}
//out.println(Arrays.toString(property));
//out.println(fileContents);
} finally {
IOUtils.closeQuietly(in);
}
}
}
} catch (SizeLimitExceededException e) {
out.println("You exceeded the maximu size ("
+ e.getPermittedSize() + ") of the file ("
+ e.getActualSize() + ")");
}
} catch (Exception ex) {
throw new ServletException(ex);
}
}
그리고 내 JSP
<form action="/upload_kind" method="post" enctype="multipart/form-data" >
<input type="file" name="file" size="50" />
<input type="text" name="namespace" id="namespace">
<br />
<input type="submit" value="Upload File" />
</form>
나는 "item.getString()"방법에 대해 읽어하지만 DiskFileItem 클래스가 아닌 FileItemStream에있어, 그래서 내가 그 "네임 스페이스를 볼 수 있습니다 "전송되지만 그 가치를 볼 수 없습니다. Thx 및 나쁜 영어로 죄송합니다.
입력 값은 무엇입니까? 이름 공간 인 경우 request.getParameter ("namespace")를 통해 가져올 수 있어야합니다. –
네임 스페이스가 있지만 "multipart/form-data"의 원인을 얻을 수 없습니다. 그것은 null을 반환합니다 – ValeMarz
가능한 [JSP/서블릿을 사용하여 서버에 파일을 업로드하는 방법?] (http://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet) –