SpringMVC 는 제3자 구성 요 소 를 사용 하여 파일 업 로드 를 실현 합 니 다.
A form 폼 의 enctype 값 은 다음 과 같 아야 합 니 다:multipart/form-data
(기본 값 은:application/x-ww-form-urlencoded)enctype:폼 요청 본문 형식 입 니 다.
B method 속성 값 은 Post 여야 합 니 다.
C 파일 선택 영역 input type=file 제공
2.제3자 구성 요 소 를 통 해 파일 업로드 실현
셋째,
/**
* springmvc
* @return
*/
@RequestMapping("/testFileUpload1")
public String testFileUpload1(MultipartFile upload) throws IOException {
System.out.println(" ...");
//
String path = "http://localhost:9090/uploads/";
//
//
String filename = upload.getOriginalFilename();
// ,uuid
String uuid = UUID.randomUUID().toString().replace("-", "");
filename = uuid+"_"+filename;
//
Client client = Client.create();
//
WebResource webResource = client.resource(path + filename);
//
webResource.put(upload.getBytes());
return "success";
}
/**
*
* upload index.jsp upload
*
* springmvc
* @return
*/
@RequestMapping("/testFileUpload")
public String testFileUpload(HttpServletRequest request, MultipartFile upload) throws IOException {
// fileupload
// ( )
String path = request.getSession().getServletContext().getRealPath("/uploads/");
// ,
File file = new File(path);
if(!file.exists()){
file.mkdir();
}
//
//
String filename = upload.getOriginalFilename();
// ,uuid
String uuid = UUID.randomUUID().toString().replace("-", "");
filename = uuid+"_"+filename;
//
upload.transferTo(new File(path,filename));
return "success";
}
4.springmvc.xml 설정 파일 해상도 기이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.