我想上传一个图像并将其存储在服务器上,然后用h:graphicImage显示它?我想将它存储在应用程序的"资源/图像"中.我正在使用glassfish 4.现在,文件转到"domain1\generated\jsp\FileUpload".谢谢
我的表格
<h:form id="form" enctype="multipart/form-data">
<h:messages/>
<h:panelGrid columns="2">
<h:outputText value="File:"/>
<h:inputFile id="file" value="#{uploadPage.uploadedFile}"/>
</h:panelGrid>
<br/><br/>
<h:commandButton value="Upload File" action="#{uploadPage.uploadFile}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我的豆子
@Named
@ViewScoped
public class UploadPage {
private Part uploadedFile;
public void uploadFile(){
File file = File.createTempFile("somefilename-", ".jpg", new File("C:\\var\\webapp\\images"));
uploadedFile.write(file.getAbsolutePath());
}
}
Run Code Online (Sandbox Code Playgroud)