开发者

Zipping a folder in remote machine running app server through J2EE app

I am working on a zipper J2EE application. This application requires the following:

The application has to zip a folder in remote machine where app server is running so that other applications can directly download this zipped folder instead of downloading each file one by one.

I am able to do this in my local machine using absolute path don't know how to go ahead with remote machine.

Code i'm using for zipping in local machine:

File file = new File(myFolderPath);    
int index = myFolderPath.lastIndexOf("/");  
String folderName =myFolderPath.substring(index);  
String folderPath = myFolderPath.substring(0, index);  
File outFolder = new File(folderPath + folderName + ".zip");  
if (!outFolder.exists()) {  
 zip(file, outFolder);  
}

H开发者_StackOverflow中文版ere myFolderPath is a string. But how should i go ahead if it is a URL? Thanks in advance.


URLs don't allow directory listings, so this is not possible. You will need absolute paths on the server, too, or convert the URL to an absoltue path on the server, maybe by replacing a http://server/ with the root folder of the webapp.


My suggestion would be to use a message driven bean for this case. You have a MDB that listens to incoming msgs on a JMS queue. The message has the folder to zip. The message bean then will call a helper that would zip the folder that is provided to the MDB. I'm basing this on the details available in your question. There is a app server running and you want the zipping action to happen on that server machine. It will be much more efficient and clean in my opinion.


The application has to zip a folder in remote machine where app server is running

I guess you have fair idea about path to the directory you wanted to zip. So code same thing what you have done locally but in servlet, create zip fiel and write the content of the zip in output stream of HttpServletResponse in order to download it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜