这是将判断文件是否存在放在一个单独的过程中,错误如下:
An error occurred at line: 7 in the jsp file: /service/upload-save.jsp
Syntax error on token "(", ; expected
7:  <%public String CheckFiles(String cFile){   
8:  String iPath=request.getRealPath("upload\\download\\");
9:  File iFile=new File(iPath,cFile);
10:  return "Path:"+ iFile +"<hr>";}如果将这两行放在程序中间,则错误如下:
An error occurred at line: 29 in the jsp file: /service/upload-save.jsp
The type File is ambiguous
28:  String iPath=request.getRealPath("upload\\download\\");
29:  File iFile=new File(iPath,UpFile.getFileName());
30:  return "Path:"+ iFile +"<hr>";

解决方案 »

  1.   

    你用System.out.println("========iPath==========="+iPath);
    和System.out.println("========UpFile==========="+UpFile.getFileName());
    打印一下看看得到什么值
      

  2.   


    前面那个,是这样的:
    <%
    public String CheckFiles(String cFile){       
    String   iPath=request.getRealPath("upload\\download\\"); 
    File   iFile=new   File(iPath,cFile); 
    return   "Path:"+   iFile   +" <hr> ";
    }
    %>
    Syntax   error   on   token   "(",   ;   expected 这个错误是差个括号。但我看几行代码,并不缺。
    如果在页面中将这几行去掉,就没有错误。你用System.out.println("========iPath==========="+iPath); 
    和System.out.println("========UpFile==========="+UpFile.getFileName()); 
    打印一下看看得到什么值
    等不到后面的显示,前面就已开始出错了。
      

  3.   

    这一段,如果放在程序中,就出错:如果不放,其他程序正常。
    其中UpFile.getFileName()是可以正常获取到值的。
    即便我将31: File iFile=new File(iPath,UpFile.getFileName());改成:
    31: File iFile=new File(iPath,"001.jpg");
    也是一样的错,其中:001.jpg确实是完整路径:D:\Tomcat\webapps\ROOT\upload\download中的一个实际存在的文件。
    如果在30行后out.print(iPath);,显示的路径就是D:\Tomcat\webapps\ROOT\upload\download\An error occurred at line: 31 in the jsp file: /service/upload-save.jsp
    The type File is ambiguous
    28: try{
    29: 
    30: String iPath=request.getRealPath("upload\\download\\");
    31: File iFile=new File(iPath,UpFile.getFileName());
    32: out.print ("Path:"+ iFile +"<hr>");
    33: 
    34: }catch(Exception e){}
      

  4.   

    你把File   iFile=new   File(iPath,UpFile.getFileName()); 
    改成File   iFile=new   File(iPath + UpFile.getFileName()); 试试