KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > javaee > blueprints > popup > DetailServlet


1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
3 * http://developer.sun.com/berkeley_license.html
4 * $Id: DetailServlet.java,v 1.1 2006/06/20 00:09:14 inder Exp $
5 */

6 /*
7  * DetailServlet.java
8  *
9  * Created on October 5, 2005, 11:32 AM
10  */

11
12 package com.sun.javaee.blueprints.popup;
13
14 import java.io.*;
15 import java.net.*;
16
17 import javax.servlet.*;
18 import javax.servlet.http.*;
19
20 /**
21  *
22  * @author basler
23  * @version
24  */

25 public class DetailServlet extends HttpServlet {
26     
27     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
28      * @param request servlet request
29      * @param response servlet response
30      */

31     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
32     throws ServletException, IOException {
33         response.setContentType("text/xml");
34         PrintWriter out = response.getWriter();
35         
36         // Get info for stock pick
37
String JavaDoc codex=request.getParameter("animalcode");
38         if(codex == null) {
39             codex="LAB";
40         }
41         String JavaDoc name="Labrador Retriever";
42         String JavaDoc descr="A breed of dog originating in Newfoundland, having a short coat and a tapering tail.";
43         String JavaDoc imagex="dog1.gif";
44         String JavaDoc lookup="labrador%20retriever";
45         
46         if(codex.equals("BULL")) {
47             name="Bulldog";
48             descr="A breed of short-haired dog characterized by a large head, strong square jaws with dewlaps, and a stocky body.";
49             imagex="dog2.gif";
50             lookup="bulldog";
51                     
52         } else if(codex.equals("BASSET")) {
53             name="Basset Hound";
54             descr="A short-haired hunting dog originating in France and having a long body, short legs, and long drooping ears.";
55             imagex="dog3.gif";
56             lookup="basset%20hound";
57                     
58         } else if(codex.equals("PUG")) {
59             name="Pug";
60             descr="A small sturdy dog having short hair, a snub nose, wrinkled face and a squarish body";
61             imagex="dog4.gif";
62             lookup="pug";
63         }
64         
65         out.println("<response>");
66         out.println("<name>" + name + "</name>");
67         out.println("<description>" + descr + "</description>");
68         out.println("<image>../images/" + imagex + "</image>");
69         out.println("<link>http://dictionary.reference.com/search?q=" + lookup + "</link>");
70         out.println("</response>");
71         out.close();
72     }
73         
74     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
75
/** Handles the HTTP <code>GET</code> method.
76      * @param request servlet request
77      * @param response servlet response
78      */

79     protected void doGet(HttpServletRequest request, HttpServletResponse response)
80     throws ServletException, IOException {
81         processRequest(request, response);
82     }
83     
84     /** Handles the HTTP <code>POST</code> method.
85      * @param request servlet request
86      * @param response servlet response
87      */

88     protected void doPost(HttpServletRequest request, HttpServletResponse response)
89     throws ServletException, IOException {
90         processRequest(request, response);
91     }
92     
93     /** Returns a short description of the servlet.
94      */

95     public String JavaDoc getServletInfo() {
96         return "Short description";
97     }
98     // </editor-fold>
99
}
100
Popular Tags