KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > javaee > blueprints > components > ui > example > CompAServlet


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: CompAServlet.java,v 1.3 2006/06/23 17:05:41 basler Exp $
5 */

6 /*
7  * CompAServlet.java
8  *
9  * Created on June 19, 2006, 10:28 AM
10  */

11
12 package com.sun.javaee.blueprints.components.ui.example;
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 CompAServlet 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;charset=UTF-8");
34         PrintWriter out = response.getWriter();
35         String JavaDoc itemId=request.getParameter("itemId");
36         
37         response.setHeader("Pragma", "No-Cache");
38         response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
39         response.setDateHeader("Expires", 1);
40         if(itemId != null) {
41             out.println("<response>");
42             if(itemId.indexOf("test1") > -1) {
43                 out.println("<title><![CDATA[" + itemId + " Lookup]]></title>");
44                 out.println("<message><![CDATA[<b>The itemId that is performing this lookup is '" + itemId +
45                         "'.</b><br/><br/>This popup is trigger through the onmouseover and onmouseout event handlers. " +
46                         "Since this popup request is fulfilled using a <b>Servlet</b>, there is an initial pause on the first request to load the class.]]></message>");
47             } else {
48                 out.println("<title><![CDATA[" + itemId + " Lookup]]></title>");
49                 out.println("<message><![CDATA[<b>The itemId that is performing this lookup is '" + itemId +
50                         "'.</b><br/><br/>This popup is trigger through the onmouseover event handler and hidden when the user clicks on the 'CLOSE' link in the popup." +
51                         "Since this popup request is fulfilled using a <b>Servlet</b>, there is an initial pause on the first request to load the class." +
52                         "<br/><br/><span onclick=\"bpui.compA.hidePopup('pop1')\" style=\"z-index: 4; position: relative; cursor: pointer\"><b>[<u>CLOSE</u>]</b></span>" +
53                         "]]></message>");
54             }
55             out.println("</response>");
56         } else {
57             out.println("<response>");
58             out.println("<title><![CDATA[REQUEST ERROR]]></title>");
59             out.println("<message><![CDATA[The query parameter 'itemId' required]]></message>");
60             out.println("</response>");
61         }
62         out.flush();
63         out.close();
64     }
65     
66     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
67
/** Handles the HTTP <code>GET</code> method.
68      * @param request servlet request
69      * @param response servlet response
70      */

71     protected void doGet(HttpServletRequest request, HttpServletResponse response)
72     throws ServletException, IOException {
73         processRequest(request, response);
74     }
75     
76     /** Handles the HTTP <code>POST</code> method.
77      * @param request servlet request
78      * @param response servlet response
79      */

80     protected void doPost(HttpServletRequest request, HttpServletResponse response)
81     throws ServletException, IOException {
82         processRequest(request, response);
83     }
84     
85     /** Returns a short description of the servlet.
86      */

87     public String JavaDoc getServletInfo() {
88         return "Short description";
89     }
90     // </editor-fold>
91
}
92
Popular Tags