开发者

WMV file downloading in jsp

I have a jsp written in which i am downloading certain files... they are pdf, zip, ppt and wmv. All the file types works except wmv. I couldnt figure out problem. When i play wmv file i get following error.

Windows Media Player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file.

In my jps i have written code as following

response.setContentType("video/x-ms-wmv");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment; filename=123.wmv;");
String fileName                 = "/logs/164266828.wmv";
FileInputStream input           = new FileInputStream(fileName);
BufferedInputStream buf      开发者_开发技巧   = new BufferedInputStream(input);
int readBytes                   = 0;
ServletOutputStream myOut       = response.getOutputStream( );
while((readBytes = buf.read( )) != -1)
    myOut.write(readBytes);

Any inputs or modifications would be of great help !!!


Do not use JSP to stream binary data. JSP may have corrupted it with template text (whitespace and so on outside those <% %> things). Move this code to the doGet() method of a servlet class and invoke the servlet instead of JSP.


Unrelated to the concrete problem, those files seems static files. You don't necessarily need a servlet for this if you have full control over your server. In case of for example Tomcat, you could add the folder with the static files as another <Context> to the server.xml file.

See also:

  • Reliable data serving
  • Simplest way to serve static data from outside the application server in a Java web application
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜