2009년 10월 26일
struts2 파일 업로드
<s:form method=post enctype=multypart/form-data ~~~>
<s:file name="upload" />
name : upload 로 해 놓을 것.
File Upload Intercept 가 context_path\work\ 에 파일을 임시 저장
해당 업로드 액션에서 파일 처리
FILE IO test...
File file = new File("c:\\hanbit\\upload");
String path = file.getPath();
String name = file.getName();
System.out.println("path : " + path);
System.out.println("name : " + name);
boolean isDir = file.isDirectory();
boolean isFile = file.isFile();
System.out.println(isDir);
System.out.println(isFile);
System.out.println(file.pathSeparatorChar);
if(isDir){
String[] fileList = file.list();
for(String resource : fileList) {
//System.out.println(resource);
String fullPathName = file.getPath() + "\\" + resource;
file = new File(fullPathName);
// 리눅스 경로 오류.. 사용 금지
file = new File(file.getPath(), resource);
file = new File(file, resource);
if(file.isFile()){
System.out.print("file : " + file.getName());
System.out.println("(" + file.length() + ")");
}
}
}
<s:file name="upload" />
name : upload 로 해 놓을 것.
File Upload Intercept 가 context_path\work\ 에 파일을 임시 저장
해당 업로드 액션에서 파일 처리
FILE IO test...
File file = new File("c:\\hanbit\\upload");
String path = file.getPath();
String name = file.getName();
System.out.println("path : " + path);
System.out.println("name : " + name);
boolean isDir = file.isDirectory();
boolean isFile = file.isFile();
System.out.println(isDir);
System.out.println(isFile);
System.out.println(file.pathSeparatorChar);
if(isDir){
String[] fileList = file.list();
for(String resource : fileList) {
//System.out.println(resource);
String fullPathName = file.getPath() + "\\" + resource;
file = new File(fullPathName);
// 리눅스 경로 오류.. 사용 금지
file = new File(file.getPath(), resource);
file = new File(file, resource);
if(file.isFile()){
System.out.print("file : " + file.getName());
System.out.println("(" + file.length() + ")");
}
}
}
# by | 2009/10/26 11:06 | 트랙백 | 덧글(0)















☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]