1 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 20 public class AccountState extends HttpServlet { 21 22 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 49 protected void doGet(HttpServletRequest request, HttpServletResponse response) 50 throws ServletException, IOException { 51 processRequest(request, response); 52 } 53 54 58 protected void doPost(HttpServletRequest request, HttpServletResponse response) 59 throws ServletException, IOException { 60 processRequest(request, response); 61 } 62 63 65 public String getServletInfo() { 66 return "Short description"; 67 } 68 70 private ejb.AccountStateLocal lookupAccountStateBean() { 71 try { 72 javax.naming.Context c = new javax.naming.InitialContext (); 73 ejb.AccountStateLocalHome rv = (ejb.AccountStateLocalHome) c.lookup("java:comp/env/ejb/AccountStateBean"); 74 return rv.create(); 75 } 76 catch(javax.naming.NamingException ne) { 77 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 78 throw new RuntimeException (ne); 79 } 80 catch(javax.ejb.CreateException ce) { 81 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 82 throw new RuntimeException (ce); 83 } 84 } 85 } 86 | Popular Tags |