Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
170
Chapter 7 Generating the Server Response: HTTP Response Headers
sage in the designated face and size, with a gray, oblique shadowed version of
the message shown behind the main string. This operation makes use of sev 
eral facilities available only in the Java 2 platform. First, it makes use of any
font that is installed on the server system, rather than limiting itself to the
standard names (
Serif
, 
SansSerif
, 
Monospaced
, 
Dialog
, and 
DialogIn 
put
) available to JDK 1.1 programs. 
Second, it uses the 
translate
, 
scale
, and 
shear
 transformations to cre 
ate the shadowed version of the main message. Consequently, the servlet will
run only in servlet engines running on the Java 2 platform. You would expect
this to be the case with engines supporting the servlet 2.2 specification, since
that is the servlet version stipulated in J2EE. 
Even if you are using a server that supports only version 2.1, you should
still use the Java 2 platform if you can, since it tends to be significantly more
efficient for server side tasks. However, many servlet 2.1 engines come pre 
configured to use JDK 1.1, and changing the Java version is not always sim 
ple. So, for example, Tomcat and the JSWDK automatically make use of
whichever version of Java is first in your 
PATH
, but the Java Web Server uses a
bundled version of JDK 1.1.
Listing 7.10 shows an HTML form used as a front end to the servlet. Fig 
ures 7 5 through 7 8 show some possible results. Just to simplify experimen 
tation, Listing 7.11 presents an interactive application that lets you specify
the message, font name, and font size on the command line, popping up a
JFrame
 that shows the same image as the servlet would return. Figure 7 9
shows one typical result. 
Listing 7.8  ShadowedText.java 
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;
/** Servlet that generates GIF images representing
 *  a designated message with an oblique shadowed
 *  version behind it.
 *  

 *  Only runs on servers that support Java 2, since
 *  it relies on Java2D to build the images.
 */
public class ShadowedText extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    String message = request.getParameter("message");
    if ((message == null) || (message.length() == 0)) {
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