O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.5. Embedding Flash in a Servlet

Problem

You want to embed a Flash file in a servlet's output.

Solution

Use the javax.servlet.RequestDispatcher.include(request,response) method in the doGet( ) method of the servlet that includes the necessary HTML template text.

Discussion

The servlet can include the HTML fragment that loads the Flash movie into the page by using a RequestDispatcher. This process is similar to server-side includes in traditional Common Gateway Interface (CGI) programs. When the servlet receives a request, it includes the text fragment containing the Flash-related tags in its HTML output. This design separates the servlet itself from the tags and parameters that load the Flash movie, so that each of these entities evolves independently. For example, you can change the filename of the Flash movie or some of the object or embed parameters without recompiling the servlet code.

Example 17-7 is a servlet that uses a RequestDispatcher to include the text shown in Example 17-8. The text appears in a flash.txt file that is stored at the top level of the web application.

Tip

RequestDispatchers typically include the output of servlets and JSPs, not just text fragments. See Chapter 6 for more detailed RequestDispatcher-related recipes.

Example 17-7. A servlet uses a RequestDispatcher to include object and embed tags

package com.jspservletcookbook; import javax.servlet.*; import javax.servlet.http.*; public class FlashServlet extends HttpServlet { public void doGet(HttpServletRequest ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required