KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > web > AccountState


1 /*
2  * AccountState.java
3  *
4  * Created on May 25, 2005, 11:35 AM
5  */

6
7 package web;
8
9 import java.io.*;
10 import java.net.*;
11
12 import javax.servlet.*;
13 import javax.servlet.http.*;
14
15 /**
16  *
17  * @author blaha
18  * @version
19  */

20 public class AccountState extends HttpServlet {
21     
22     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
23      * @param request servlet request
24      * @param response servlet response
25      */

26     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
27     throws ServletException, IOException {
28         response.setContentType("text/html;charset=UTF-8");
29         PrintWriter out = response.getWriter();
30         out.println("<html>");
31         out.println("<head>");
32         out.println("<title>Servlet AccountState</title>");
33         out.println("</head>");
34         out.println("<body>");
35         out.println("<h1>Servlet AccountState at " + request.getContextPath () + "</h1>");
36         
37         out.println(lookupAccountStateBean().getStatus(request.getUserPrincipal().getName()));
38         
39         out.println("</body>");
40         out.println("</html>");
41         out.close();
42     }
43     
44     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
45
/** Handles the HTTP <code>GET</code> method.
46      * @param request servlet request
47      * @param response servlet response
48      */

49     protected void doGet(HttpServletRequest request, HttpServletResponse response)
50     throws ServletException, IOException {
51         processRequest(request, response);
52     }
53     
54     /** Handles the HTTP <code>POST</code> method.
55      * @param request servlet request
56      * @param response servlet response
57      */

58     protected void doPost(HttpServletRequest request, HttpServletResponse response)
59     throws ServletException, IOException {
60         processRequest(request, response);
61     }
62     
63     /** Returns a short description of the servlet.
64      */

65     public String JavaDoc getServletInfo() {
66         return "Short description";
67     }
68     // </editor-fold>
69

70     private ejb.AccountStateLocal lookupAccountStateBean() {
71         try {
72             javax.naming.Context JavaDoc c = new javax.naming.InitialContext JavaDoc();
73             ejb.AccountStateLocalHome rv = (ejb.AccountStateLocalHome) c.lookup("java:comp/env/ejb/AccountStateBean");
74             return rv.create();
75         }
76         catch(javax.naming.NamingException JavaDoc ne) {
77             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
78             throw new RuntimeException JavaDoc(ne);
79         }
80         catch(javax.ejb.CreateException JavaDoc ce) {
81             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
82             throw new RuntimeException JavaDoc(ce);
83         }
84     }
85 }
86
Popular Tags