내 UI 페이지에서 enctype = "multipart/form-data"및 인코딩 = "multipart/form- 데이터 "내 HTML 양식에.파일을 아파치를 통해 전달할 때 스프링 컨트롤러를 사용하여 Multipart 파일을 읽을 수 없습니다. httpclient
org.apache.commons.fileupload.servlet.ServletFileUpload API를 사용하여 내 서버 클래스 (서블릿)에서 파일 내용을 성공적으로 읽을 수 있습니다.
그 후 파일 또는 해당 내용을 다른 서버에 전달하려고합니다. muttpart 옵션을 사용하여 아파치 Commons Httpclient를 사용하면 내용이 다른 레이어로 전달되는지 확인할 수 있습니다 (요청 본문 내용을 확인하거나 Chrome 개발자 도구에서 요청)
하지만 스프링 서버를 기반으로하는 다른 서버 레이어에서는 업로드 된 파일을 통해 업로드 할 수 있지만 내용은 가져 오지 못합니다. "필요한 MultipartFile 매개 변수 'fileContents'가 없습니다."라는 메시지가 표시됩니다.
스프링 컨트롤러에서 파일을 가져 오지 못해서 어떤 문제가 될 수 있는지 알려주세요. 상황에 config.xml의 내부
HttpMethod httpMethod = new PostMethod(epsURL);
String contentTypeRequested = request.getContentType();
httpMethod.setRequestHeader("Content-type", contentTypeRequested);
if(isMultipart){
String content = getUploadFileContents(request);
File file = null;
try {
file = new File("fileContents");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw;
fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content.toString());
bw.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try{
Part[] parts = {
new FilePart(file.getName(), file)
};
MultipartRequestEntity multipart = new MultipartRequestEntity(parts, httpMethod.getParams());
((PostMethod) httpMethod).setRequestEntity(multipart);
}catch(Exception e){
e.printStackTrace();
}
}
2.Spring 층의 변화 :
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000"/>
<property name="maxInMemorySize" value="100000"/>
</bean>
다른 서버에 파일을 게시
서버 클래스/서블릿 구현
3. 스프링 컨트롤러 구현 :
@RequestMapping(method = RequestMethod.POST, value = "/type/details") public void getTypeDetails( @RequestParam("fileContents") MultipartFile file, HttpServletRequest httpRequest) { /// some business logic here based on file object. }
나는 아래의 오류가 점점 오전 :
오류 : 2014년 4월 16일 16 : 28 : 51,638 [HTTP 바이오-8080-간부-2] 오류 com.MyControllerImpl - 예외 발생했습니다 : org.springframework.web.bind.MissingServletRequestParameterException : 필수의 MultipartFile 매개 변수 '된 FileContents가'org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue에 존재하지 않는 (RequestParamMethodArgumentResolver.java:208)
비슷한 문제가 있습니다. 어떤 해결책을 찾았습니까? –