1 6 7 package test; 8 9 import java.io.*; 10 import java.net.*; 11 import java.rmi.RemoteException ; 12 import java.util.logging.Level ; 13 import java.util.logging.Logger ; 14 import javax.ejb.CreateException ; 15 import javax.naming.Context ; 16 import javax.naming.InitialContext ; 17 import javax.naming.NamingException ; 18 import javax.rmi.PortableRemoteObject ; 19 20 import javax.servlet.*; 21 import javax.servlet.http.*; 22 23 28 public class TestingServlet extends HttpServlet { 29 30 34 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 35 throws ServletException, IOException { 36 response.setContentType("text/html;charset=UTF-8"); 37 PrintWriter out = response.getWriter(); 38 out.println("<html>"); 39 out.println("<head>"); 40 out.println("<title>Servlet TestingServlet</title>"); 41 out.println("</head>"); 42 out.println("<body>"); 43 out.println("<h1>Servlet TestingServlet at " + request.getContextPath () + "</h1>"); 44 out.println("</body>"); 45 out.println("</html>"); 46 out.close(); 47 } 48 49 54 protected void doGet(HttpServletRequest request, HttpServletResponse response) 55 throws ServletException, IOException { 56 processRequest(request, response); 57 } 58 59 63 protected void doPost(HttpServletRequest request, HttpServletResponse response) 64 throws ServletException, IOException { 65 processRequest(request, response); 66 } 67 68 70 public String getServletInfo() { 71 return "Short description"; 72 } 73 75 private TestingSessionRemote lookupTestingSessionBean() { 76 try { 77 Context c = new InitialContext (); 78 Object remote = c.lookup("java:comp/env/ejb/TestingSessionBean"); 79 TestingSessionRemoteHome rv = (TestingSessionRemoteHome) PortableRemoteObject.narrow(remote, TestingSessionRemoteHome.class); 80 return rv.create(); 81 } 82 catch(NamingException ne) { 83 Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne); 84 throw new RuntimeException (ne); 85 } 86 catch(CreateException ce) { 87 Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ce); 88 throw new RuntimeException (ce); 89 } 90 catch(RemoteException re) { 91 Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,re); 92 throw new RuntimeException (re); 93 } 94 } 95 } 96
| Popular Tags
|