大家好! 我想使用下面的代码 !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);
}
}
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);
}
}
解决方案 »
- js如何生成一个新的html页面、?
- 请帮我解释下URL
- 有没支持直接粘贴的网页控件
- java导数据时失败
- 初学spring 遇到的第一个问题,请高手指点
- 急问我的history.go("Test");为什么不好使??
- 关于java.awt.*包的用法请教(在线等待..............)
- 如何在HTML文件中包含JSP文件?
- jsp中知道一个变量 year=1999;查找year表的select语句怎么写("select * from ....")
- jsp调用JavaBeans出现的错误!请高手指点。。
- 求助初用Tomcat的一点问题
- 导出的excel报表中,想画线,应该如何做?高分求教!
把上段代码拷贝进去就可以用了。
<%!
public static void renameAllFiles(String path, boolean needLowerCase) {
}
%><%
//在这可直接调用上面的方法
%>外部Bean用
<jsp:useBean id="dbBean" scope="page" class="dbconn.DbBean"/>
比如:我把他放到一个名为test的类里面
public class test{
public static void renameAllFiles(String path, boolean needLowerCase) {
.....}
}然后在页面用如下方法调用
<%
test t = new test();
t.renameAllFiles(参数1,参数2);
%>
-------------------------------------------------------------------------------
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);
%>
在页面调用时:页面上加<jsp:useBean id="可随便写个名字比如:DB" scope="page" class="类所在路径"/>
那么在下面调用的时候就可以直接:DB.方法名(参数1,参数2);
上面是静态方法所以可以直接这样写.
如果在其它BEAN中调用:improt ....;引入新建的类.
调用时:类名.方法名(参数1,参数2)
包是放在WEB-INF\classes\
就行