1 6 7 package test; 8 9 import java.io.*; 10 import java.net.*; 11 12 import javax.servlet.*; 13 import javax.servlet.http.*; 14 15 20 public class TestServlet 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 TestServlet</title>"); 33 out.println("</head>"); 34 out.println("<body>"); 35 out.println("<h1>Servlet TestServlet at " + request.getContextPath () + "</h1>"); 36 out.println(lookupTestSessionBean1().testMethod()); 37 out.println("</body>"); 38 out.println("</html>"); 39 out.close(); 40 } 41 42 47 protected void doGet(HttpServletRequest request, HttpServletResponse response) 48 throws ServletException, IOException { 49 processRequest(request, response); 50 } 51 52 56 protected void doPost(HttpServletRequest request, HttpServletResponse response) 57 throws ServletException, IOException { 58 processRequest(request, response); 59 } 60 61 63 public String getServletInfo() { 64 return "Short description"; 65 } 66 68 private test.TestSessionLocal lookupTestSessionBean1() { 69 try { 70 javax.naming.Context c = new javax.naming.InitialContext (); 71 test.TestSessionLocalHome rv = (test.TestSessionLocalHome) c.lookup("java:comp/env/ejb/TestSessionBean1"); 72 return rv.create(); 73 } 74 catch(javax.naming.NamingException ne) { 75 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 76 throw new RuntimeException (ne); 77 } 78 catch(javax.ejb.CreateException ce) { 79 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 80 throw new RuntimeException (ce); 81 } 82 } 83 } 84 | Popular Tags |