Hi. what's the recommended method to load an SWF file in my page ?
just to use HttpServletResponse.getWriter and to print with it the SWF object, or is there a more efficient method ?
Hi. what's the recommended method to load an SWF file in my page ?
just to use HttpServletResponse.getWriter and to print with it the SWF object, or is there a more efficient method ?
If it is a static SWF file, simply place it in a publicly browsable path and allow Tomcat to serve it as a static file. If you are generating an SWF file dynamically, ServletResponse.getWriter()
is perfectly fine as long as you remember to set the Content-type
HTTP header to application/x-shockwave-flash
. You can do that just before writing to the output stream with ServletResponse.setContentType()
like this:
resp.setContentType("application/x-shockwave-flash");
You may also want to think about setting some HTTP caching related headers such as Cache-Control
and Expires
if you want browsers to be able to cache your SWF files. You can do that with HttpServletResponse.setHeader()
or HttpServletResponse.addHeader()
. For the case of a static SWF file, you will have to set caching headers in a Filter
mapped with a <url-pattern>
.
Another point worth mentioning is that referencing SWF content in a cross browser friendly way that bypasses an irritating extra-click behavior in some versions of MSIE has become some kind of black magic. I recommend using the SWFObject library (hosted on Google Code) to abstract the ugliness away.