No wiki tem varios exemplos...
mport java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DownloadAction;
public class FileDownloadAction extends DownloadAction {
protected Logger log=Log.getLogger(FileDownloadAction.class.getSimpleName());
/*
* (non-Javadoc)
* @see org.apache.struts.actions.DownloadAction#getStreamInfo(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected StreamInfo getStreamInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
String filePath = arg2.getParameter("uri");
StringBuffer buffer = new StringBuffer();
String path = null;
if (filePath != null) {
String http = ConfigConstants.getResourceBundle().getString(
"HTTP_URL");
buffer.append(http);
buffer.append(filePath);
path=buffer.toString();
}
log.finest("Path name is :" + path);
String contentType = "application/x-msexcel";
return new SI(contentType, new URL(path));
}
/**
*
* @author nsuj
*
*/
public static class SI implements StreamInfo {
private String contentType;
private URL file;
public SI(String contentType, URL file) {
this.contentType = contentType;
this.file = file;
}
public String getContentType() {
return this.contentType;
}
/**
* Method to get a stream on the file to download
*
* @return The InputStream wrapping the file to download
*
*/
public InputStream getInputStream() throws IOException {
return file.openStream();
}
}
}
[url]http://forum.java.sun.com/thread.jspa?threadID=655374&messageID=4120857[/url]