01: package webclient;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: public class HelloServlet extends HttpServlet {
11:
12: /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
13: * @param request servlet request
14: * @param response servlet response
15: */
16: protected void processRequest(HttpServletRequest request,
17: HttpServletResponse response) throws ServletException,
18: IOException {
19: String username = request.getParameter("username");
20: response.setContentType("text/html;charset=UTF-8");
21: PrintWriter out = response.getWriter();
22: out.println("<html>");
23: out.println("<head>");
24: out.println("<title>HelloServlet</title>");
25: out.println("</head>");
26: out.println("<body>");
27: if (username != null && username.length() > 0) {
28: try {
29: out.println("<img src=\"duke.waving.gif\">");
30: out.println("<h2><font color=\"black\">");
31: out.println(getHelloSEIPort().sayHello(username));
32: out.println("</font></h2>");
33: } catch (java.rmi.RemoteException ex) {
34: ex.printStackTrace(out);
35: }
36: } else {
37: out.println("You didn't specify your name.<br/>");
38: }
39: out.println("<a href=\"index.jsp\">back</a>");
40: out.println("</body>");
41: out.println("</html>");
42: out.close();
43: }
44:
45: // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
46: /** Handles the HTTP <code>GET</code> method.
47: * @param request servlet request
48: * @param response servlet response
49: */
50: protected void doGet(HttpServletRequest request,
51: HttpServletResponse response) throws ServletException,
52: IOException {
53: processRequest(request, response);
54: }
55:
56: /** Handles the HTTP <code>POST</code> method.
57: * @param request servlet request
58: * @param response servlet response
59: */
60: protected void doPost(HttpServletRequest request,
61: HttpServletResponse response) throws ServletException,
62: IOException {
63: processRequest(request, response);
64: }
65:
66: /** Returns a short description of the servlet.
67: */
68: public String getServletInfo() {
69: return "Short description";
70: }
71:
72: // </editor-fold>
73:
74: private webclient.Hello getHello() {
75: webclient.Hello hello = null;
76: try {
77: javax.naming.InitialContext ic = new javax.naming.InitialContext();
78: hello = (webclient.Hello) ic
79: .lookup("java:comp/env/service/Hello");
80: } catch (javax.naming.NamingException ex) {
81:
82: }
83: return hello;
84: }
85:
86: private webclient.HelloSEI getHelloSEIPort() {
87: webclient.HelloSEI helloSEIPort = null;
88: try {
89: helloSEIPort = getHello().getHelloSEIPort();
90: } catch (javax.xml.rpc.ServiceException ex) {
91:
92: }
93: return helloSEIPort;
94: }
95: }
|