相关疑难解决方法(0)

如何将文件写入应用程序的资源/图像文件夹?

我想上传一个图像并将其存储在服务器上,然后用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)

jsf file-upload glassfish jsf-2.2

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

file-upload ×1

glassfish ×1

jsf ×1

jsf-2.2 ×1