11

画像をアップロードしてサーバーに保存し、後で 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>

私の豆

@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());

    }
}
4

2 に答える 2