Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在PrimeFaces3和jsf中,我上传了文件,但在目标位置,图像没有显示_Java_Jsf_Primefaces - Fatal编程技术网

Java 在PrimeFaces3和jsf中,我上传了文件,但在目标位置,图像没有显示

Java 在PrimeFaces3和jsf中,我上传了文件,但在目标位置,图像没有显示,java,jsf,primefaces,Java,Jsf,Primefaces,我使用了简单模式,glassfish 3.0和primefaces 3.0 背豆 私有上传文件; 专用字符串destination=“D:\temp\” 公共无效上载(FleUploadEvent事件){ public void copyFile(字符串文件名,InputStream-in){ 试一试{ // write the inputStream to a FileOutputStream OutputStream out = new File

我使用了简单模式,glassfish 3.0和primefaces 3.0

背豆

私有上传文件; 专用字符串destination=“D:\temp\”

公共无效上载(FleUploadEvent事件){

public void copyFile(字符串文件名,InputStream-in){ 试一试{

           // write the inputStream to a FileOutputStream
            OutputStream out = new FileOutputStream(new File(destination + fileName));

         int read = 0;
       byte[] bytes = new byte[1024];

        while ((read = in.read(bytes)) != -1) {
             out.write(bytes, 0, read);
         }

         in.close();
       out.flush();
         out.close();

    System.out.println("New file created!");
        } catch (IOException e) {
      System.out.println(e.getMessage());
      }
}

这是我的jsf页面


在您的示例中,“D:\tmp\”后面是上载文件的完整文件名,即“C:\Users\admin\Desktop\image.jpg”。 这是不正确的,并导致错误。 您所需要的只是处理上传的文件名:提取实际名称而不包含路径信息。 例如,您可以使用以下内容:

if (fileName.indexOf("/")>0){
  fileName = fileName.substring(fileName.lastIndexOf("/"));
}
OutputStream out = new FileOutputStream(new File(destination + fileName));

在copyFile方法中。

请帮助任何主体将其未显示在目标位置的图像显示以下消息显示未生成任何异常或错误仅显示简单消息“D:\tmp\C:\Users\admin\Desktop\lucerimage.jpg(文件名、目录名或卷标语法不正确)”我使用的是上面相同的代码,所以请在目的地告诉我文件还没有上传有你的文件字段设置器和getter方法吗?可能会帮助你以下链接:先生,我在jsf页面中使用上述链接中的这些代码,我无法设置到目的地Nady Nikolaev先生,我正在尝试你定义的上述代码但是我没有在目的地显示图像我不确定我是否完全理解你的意思。没有显示-你的意思是目的地没有图像?出现了一些异常情况?Gennady Nikolaev先生,我发现我的问题是浏览器问题,我使用的是IE11浏览器,在mozila和IE9、IE10中工作正常,所以感谢sir在目的地显示这些图像EMP文件夹,但如何在我的sql数据库中显示这些图像我使用的是mysql 5.0,请帮助任何人这些图像上传到IE10浏览器的目的地,但不上传到IE9浏览器请帮助我在这里卡住了
if (fileName.indexOf("/")>0){
  fileName = fileName.substring(fileName.lastIndexOf("/"));
}
OutputStream out = new FileOutputStream(new File(destination + fileName));