Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
7.5 Using Servlets to Generate GIF Images
171
Listing 7.8  ShadowedText.java (continued)
      message = "Missing 'message' parameter";
    }
    String fontName = request.getParameter("fontName");
    if (fontName == null) {
      fontName = "Serif";
    }
    String fontSizeString = request.getParameter("fontSize");
    int fontSize;
    try {
      fontSize = Integer.parseInt(fontSizeString);
    } catch(NumberFormatException nfe) {
      fontSize = 90;
    }
    response.setContentType("image/gif");
    OutputStream out = response.getOutputStream();
    Image messageImage =
      MessageImage.makeMessageImage(message,
                                    fontName,
                                    fontSize);
    MessageImage.sendAsGIF(messageImage, out);
  }
  /** Allow form to send data via either GET or POST. */
  
  public void doPost(HttpServletRequest request,
                     HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }
}
Listing 7.9  MessageImage.java 
package coreservlets;
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import Acme.JPM.Encoders.GifEncoder;
/** Utilities for building images showing shadowed messages.
 *  Includes a routine that uses Jef Poskanzer's GifEncoder
 *  to return the result as a GIF.
 *  

 *  Does not run in JDK 1.1, since it relies on Java2D
 *  to build the images.
 *  

 */
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved