I would like to upload an image and store it on the server, and later to show it with h:graphicImage? I would like to store it in "resources/images" of the app. I am using glassfish 4. Right now, the file goes to "domain1generatedjspFileUpload". Thank you
My form
<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>
My bean
@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());
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…