1 6 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 25 public class DetailServlet extends HttpServlet { 26 27 31 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 32 throws ServletException, IOException { 33 response.setContentType("text/xml"); 34 PrintWriter out = response.getWriter(); 35 36 String codex=request.getParameter("animalcode"); 38 if(codex == null) { 39 codex="LAB"; 40 } 41 String name="Labrador Retriever"; 42 String descr="A breed of dog originating in Newfoundland, having a short coat and a tapering tail."; 43 String imagex="dog1.gif"; 44 String 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 79 protected void doGet(HttpServletRequest request, HttpServletResponse response) 80 throws ServletException, IOException { 81 processRequest(request, response); 82 } 83 84 88 protected void doPost(HttpServletRequest request, HttpServletResponse response) 89 throws ServletException, IOException { 90 processRequest(request, response); 91 } 92 93 95 public String getServletInfo() { 96 return "Short description"; 97 } 98 } 100 | Popular Tags |