2011-05-03 65 views
0

在Java中有使用exec方法执行递归触摸的方法吗?需要帮助从Java JSP运行递归触摸

目标是设置一个简单的网页,当重新加载将触摸该网站的目录,以便设计可以保证缓存不再发生。请任何帮助!

这里是我到目前为止,在我的JSP不工作:

<%@ page import="java.io.BufferedReader,java.io.File,java.io.FileWriter, java.io.IOException, java.io.InputStreamReader, java.util.Map" %> 

<% 


String s = null; 
// system command to run 
String cmd = "find /home/abcdefg/ -exec touch {} \\;"; 
// set the working directory for the OS command processor 
File workDir = new File("/home/ss/public_html/ss"); 

try { 
Process p = Runtime.getRuntime().exec(cmd, null, workDir); 
int i = p.waitFor(); 
if (i == 0){ 
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); 
// read the output from the command 
while ((s = stdInput.readLine()) != null) { 
System.out.println(s); 
} 
} 
else { 
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); 
// read the output from the command 
while ((s = stdErr.readLine()) != null) { 
System.out.println(s); 
} 

} 
} 
catch (Exception e) { 
System.out.println(e); 
} 


%> 
+2

我认为这将是最好附加一个随机参数?U = 12345 URL,这样浏览器就看不到网址作为可缓存,并且当过你想“触摸功能改变参数值“另外,不要把java代码放在jsp中。将java代码放入java类中,并使用el调用approprate方法。 – MeBigFatGuy 2011-05-03 04:58:03

+0

完全同意。这更像是一个快速实用的页面,让我的Javascript小伙子能够在他的改变总是没有他的困扰下重新开始;-)。 – DanielCW 2011-05-04 02:25:20

回答

0

所有沿相同的路径 - 我想出的答案,它靠近你guys posted:

<% String [] cmd = {“/ bin/sh”,“-c”,“cd/xx/xx/xx/xx; find。-exec touch {} \;}} ; 进程p = Runtime.getRuntime()。exec(cmd); %>

谢谢各位快速回复!

丹尼尔

1

你真的想摸摸/home/abcdefg下的文件?我可以想象你想要触摸​​下的所有文件。如果是这样的话,你必须改变find命令:

String cmd = "find /home/ss/public_html/ss -exec touch {} \\;" 
1

尝试不同的命令参数:

// system command to run 
String[] cmd = {"find","/home/abcdefg/","-exec","touch","{}",";"};