The HttpServletResponse object that Tomcat passes to the servlet provides access to an OutputStream object, and I see no way to set the filename with an object of that class. If Tomcat passed a FileOutputStream object (child of OutputStream), I could call a constructor that sets the file name or file descriptor, but casting the OutputStream to a FileOutputStream is not permitted. According to the API, the OutputStream object that Tomcat passess to the servlet is actually a ServletOutputStream object, which is an abstract child of OutputStream. Is there a concrete child of ServletOutputStream that I could cast it to, that would let me specify the filename? Is this something configurable in Tomcat? Any other way to set the filename?
Here's my servlet code.
package FileSnatcher;
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import javax.activation.MimetypesFileTypeMap;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FileSender extends HttpServlet{ protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{ String file = request.getParameter("file"); MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap
("C:\\Program Files\\Java\\jdk1.5.0_01\\lib\\mime.types");
String mime = mimeTypes.getContentType(new File(file));
response.setContentType(mime); FileInputStream in = new FileInputStream(new File(file));
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int i = 0;
while((i=in.read(buf))!=-1) {
out.write(buf, 0, i);
}
in.close();
out.close();
}
}--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
