大家好! 我想使用下面的代码 !jsp+javabean 怎么样连接呢? 请大家帮帮忙!public static void renameAllFiles(String  path,  boolean  needLowerCase)  {  
   try  {  
   File  file  =  new  File(path);  
   if  (!file.exists())  
   return;  
   if  (!file.isDirectory())  
   return;  
   String[]  tempList  =  file.list();  
   File  temp  =  null;  
   File  destinationFile  =  null;  
   for  (int  i  =  0;  i  <  tempList.length;  i++)  {  
   System.out.println(tempList[i]);  
   //防止文件路径中有空格,生成要重命名的文件对象  
   if  (path.endsWith(File.separator))  
   temp  =  new  File(path  +  tempList[i]);  
   else  
   temp  =  new  File(path  +  File.separator  +  tempList[i]);  
   //设定修改的规则:大写或者小写  
   if  (needLowerCase)  
   tempList[i]  =  tempList[i].toLowerCase();  
   else  
   tempList[i]  =  tempList[i].toUpperCase();  
   //根据规则,产生虚拟的新文件对象              
   if  (path.endsWith(File.separator))  
   destinationFile  =  new  File(path  +  tempList[i]);  
   else  
   destinationFile  =  
   new  File(path  +  File.separator  +  tempList[i]);  
   if  (temp.isFile())  
   temp.renameTo(destinationFile);  
   if  (temp.isDirectory())  
   renameAllFiles(path  +  tempList[i],  needLowerCase);  
   }      }  
   catch  (Exception  e)  {  
   System.out.println(e);  
   }  
}

解决方案 »

  1.   

    新建一个JavaBeans或在已有的JavaBeans里,
    把上段代码拷贝进去就可以用了。
      

  2.   

    在页面里面
    <%!
       public static void renameAllFiles(String  path,  boolean  needLowerCase)  {   
       }
    %><%
       //在这可直接调用上面的方法
         
    %>外部Bean用
    <jsp:useBean id="dbBean" scope="page" class="dbconn.DbBean"/>
      

  3.   

    直接在jsp文件里实例化这个bean不就可以了?
      

  4.   

    你把他放到一个类里面,然后在要调用的地方建立对象,然后调用这个方法
    比如:我把他放到一个名为test的类里面
    public class test{ 
      public static void renameAllFiles(String  path,  boolean  needLowerCase)  {   
     .....}
    }然后在页面用如下方法调用
    <%
    test t = new test();
    t.renameAllFiles(参数1,参数2);
    %>
      

  5.   

    如果你的JAVA方法重复使用的次数比较多,建议你建立一个JAVABean。如果你用JSP+JAVABean的话,我建议你不要把JAVA的逻辑代码写到JSP页面中。这样有利于修改或者扩展功能。某一JSP页面,需要调用你所编写的方法的时候。如果这个JAVABean没有包,可以直接在页面实例化,如果有包,就    import.包名.*   就可以正常使用,建议你买些书。开始学,最好要把基本功打好。
      

  6.   

    ymjkk(楷楷) =>我按照你的方法去做了 但是出了错!
    -------------------------------------------------------------------------------
    Please remove or make sure it appears in the correct subdirectory of the classpath.
          test.TestFiles test = null;
    ----------------------------------------------------------------------------
    File.jsp:<jsp:useBean id="test" scope="page" class="test.TestFiles"/>
    <%
    String path="e:\\test";
    test2.renameAllFiles(path);
    %>
      

  7.   

    你照我的写法来做,应该是没问题的,但是记得要引入CLASS所在的包!
      

  8.   

    <jsp:useBean id="test" scope="page" class="test.TestFiles"/>我的方法不用写这一句!
      

  9.   

    新建一个类,把上面的方法直接放到你所建的类,中;
    在页面调用时:页面上加<jsp:useBean id="可随便写个名字比如:DB" scope="page" class="类所在路径"/>
    那么在下面调用的时候就可以直接:DB.方法名(参数1,参数2);
    上面是静态方法所以可以直接这样写.
    如果在其它BEAN中调用:improt ....;引入新建的类.
    调用时:类名.方法名(参数1,参数2)
      

  10.   

    ymjkk(楷楷)=>怎么引入阿?用import ? 我没用过 请指教 !
      

  11.   

    用 import 包名.类名
    包是放在WEB-INF\classes\
    就行