RichFaces 파일 업로드
public String uploadListener(UploadEvent event) {
String url;
UploadItem item = event.getUploadItem();
String fileName = item.getFileName();
System.out.println("fileName:"+fileName);
int a = fileName.lastIndexOf(".");
//
String ext = fileName.substring(a+1);
System.out.println("ext:"+ext);
SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
//
String fileNewName=matter.format(System.currentTimeMillis())+"."+ext;
System.out.println("fileNewname:"+fileNewName);
try {
String filepath = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/")+ "upload"+"/";
System.out.println("filePath:"+filepath);
File file = new File(filepath, fileName);
FileInputStream fis = new FileInputStream(item.getFile());
FileOutputStream out = new FileOutputStream(file);
int bytes = 0;
byte[] bteFile = new byte[1024];
while ((bytes = fis.read(bteFile)) != -1) {
out.write(bteFile, 0, bytes);
}
} catch (Exception e) {
}
url = "upload" + "/" +fileNewName;
System.out.println("url:"+url);
return url;
}
Java 코드:
<h:form>
<h:panelGroup>
<h:outputText value=" "></h:outputText>
<rich:spacer height="3" />
<rich:fileUpload fileUploadListener="#{MyBean.uploadListener}"
maxFilesQuantity="5"
autoclear="false"
addControlLabel=" "
uploadControlLabel=" "
clearAllControlLabel=" "
clearControlLabel=" "
cancelEntryControlLabel=" "
stopControlLabel=" "
stopEntryControlLabel=" " noDuplicate="true"
id="upload"
>
<h:outputText value="{_KB}KB from {_KB}KB uploaded --- {mm}:{ss}" />
</rich:fileUpload>
</h:panelGroup>
</h:form>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
IBM Portal에서 자동 JSP 재부팅 활성화포털 서버를 다시 시작하지 않고 주제와 외관 JSP에 대한 변경 사항을 보려면 응용 프로그램 서버에서 JSP의 새 버전을 자동으로 검사하도록 강제할 수 있습니다.이것은 개발과 테스트 목적에 이상적이지만 성능 문제로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.