1 5 6 package helloweb; 7 8 import java.io.*; 9 import java.net.*; 10 11 import javax.servlet.*; 12 import javax.servlet.http.*; 13 14 18 public class HelloWebServlet extends HttpServlet { 19 20 24 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 25 throws ServletException, IOException { 26 response.setContentType("text/html;charset=UTF-8"); 27 PrintWriter out = response.getWriter(); 28 29 30 out.println("<html>"); 31 out.println("<head>"); 32 out.println("<title>Servlet HelloWebServlet</title>"); 33 out.println("</head>"); 34 out.println("<body>"); 35 out.println("<p>Enter your name:"); 36 out.println("<form method=\"get\">"); 37 out.println("<input type=\"text\" name=\"name\" size=\"25\">"); 38 out.println("<br>"); 39 out.println("<p>"); 40 out.println("<input type=\"submit\" value=\"Submit\">"); 41 out.println("</form>"); 42 String name = request.getParameter("name"); 43 if ( name != null ) { 44 try { 45 out.println(getHelloServiceSEIPort().sayHello(name)); 46 } catch(java.rmi.RemoteException ex) { 47 out.println("<p>Caught an exception <p>" + ex); 48 } 49 } 50 out.println("</body>"); 51 out.println("</html>"); 52 53 out.close(); 54 } 55 56 61 protected void doGet(HttpServletRequest request, HttpServletResponse response) 62 throws ServletException, IOException { 63 processRequest(request, response); 64 } 65 66 70 protected void doPost(HttpServletRequest request, HttpServletResponse response) 71 throws ServletException, IOException { 72 processRequest(request, response); 73 } 74 75 77 public String getServletInfo() { 78 return "Short description"; 79 } 80 82 private helloweb.HelloService getHelloService() { 83 helloweb.HelloService helloService = null; 84 try { 85 javax.naming.InitialContext ic = new javax.naming.InitialContext (); 86 helloService = (helloweb.HelloService) ic.lookup("java:comp/env/service/HelloService"); 87 } catch(javax.naming.NamingException ex) { 88 } 90 return helloService; 91 } 92 93 private helloweb.HelloServiceSEI getHelloServiceSEIPort() { 94 helloweb.HelloServiceSEI helloServiceSEIPort = null; 95 try { 96 helloServiceSEIPort = getHelloService().getHelloServiceSEIPort(); 97 } catch(javax.xml.rpc.ServiceException ex) { 98 } 100 return helloServiceSEIPort; 101 } 102 } 103 | Popular Tags |