有两个问题:
第1个问题: 我用jspSmartUpload做的上传文件到服务器的mySQL数据库里,保存输入的文本信息都没有问题,当我要从本地上传一个图片文件到服务器端的数据库里时候总是有问题,错误信息如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /upload.jsp at line 5956:     //store the upload file in the databank
57:      
58:     file = new java.io.File(fullName);
59:     fis = new java.io.FileInputStream(file);
60: //   out.println(file.length());
61:    }
62:     //open the databankjava.io.FileNotFoundException: F:\private\bank\bank\images\bg.jpg (No such file or directory)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
org.apache.jsp.upload_jsp._jspService(upload_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)我的upload.jsp里一段相应程序是:
         ...
String myFileName = "";
String fullName = "";
String editor = (String) request.getSession().getAttribute("logUserName");

java.io.File file = null;
java.io.FileInputStream fis = null;
  
   if (!myFile.isMissing())
    {
   //get the name of the upload file
    myFileName = myFile.getFileName();
    fullName = myFile.getFilePathName();
    System.out.println("fullName = " + fullName);
    //get the name the file without suffix
    String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
    //get suffix of the file
    String  ext= mySmartUpload.getFiles().getFile(0).getFileExt();  
    //get the size of the file  
    int fileSize=myFile.getSize();
    //store the path
    //String aa=getServletContext().getRealPath("/")+"jsp\\";
    //String trace=aa+myFileName;
    //get other parameters
    //String send=(String)mySmartUpload.getRequest().getParameter("send");
    //store the file in server 
    //myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
    
    //store the upload file in the databank
     
    file = new java.io.File(fullName);
    fis = new java.io.FileInputStream(file);
//   out.println(file.length());
   }第2个:同样也是文件上传问题,jsp文件里有个打开文本文件并提取其中内容的功能,但是程序部署到服务器后,打不开本地的文件,错误的jsp内容:
The content of the file 'F:\private\bank\bank\images\search.jpg ' : Error: The file 'F:\private\bank\bank\images\search.jpg' does not exists. 
Do you want to look at another file? 
相应的程序:
<% if (file_reader.getFileName() != "") { %> <b>The content of the file '</b><% out.println(file_reader.getFileName()); %><b>' : </b>
<br><br> 这些问题当在本机上运行程序时候都不存在,当把程序发布到服务器端后才出现的问题,估计是相对路径的设置问题,请教各位高手应该怎么修改程序,小弟谢谢了!!

解决方案 »

  1.   

     F:\private\bank\bank\images\你去建一个这样的目录看看
      

  2.   

    java.io.FileNotFoundException: F:\private\bank\bank\images\bg.jpg (No such file or directory) 找不到bg.jpg文件,你没有出路路径,只有文件名,所以需要有F:\private\bank\bank\images\ 存在;
    另外:建议用相对的路径!
      

  3.   

    晕呀,服务器是不能读你本地的文件的呀,它是绝对不能FileInputStream来读取的,除非web服务器在本地
    看一下,这个帖子吧
    http://topic.csdn.net/u/20080605/17/22078447-285a-4536-aecc-7284e19baced.html
      

  4.   


    F:\private\bank\bank\images\ 这个路径在本机上是存在的,文件也都有。另请教如何使用相对路径
      

  5.   


    本机上你测试了没有?成功了没有?建议用struts自带的FileForm
      

  6.   

    相对路径就是前缀不要加"/",比如C:/test.txt->test.txt或者../test.txt
      

  7.   

    可是我的文件路径不是自己写上去的,而是通过jsp上文件浏览,然后在本地机器上打开文件,然后上载的。这要怎么改,才能让程序找本机路径下的文件,而不是找主机路径下的文件?怎么换成相对路径的形式?