001: /*
002: * HelloWebServlet.java
003: *
004: */
005:
006: package helloweb;
007:
008: import java.io.*;
009: import java.net.*;
010:
011: import javax.servlet.*;
012: import javax.servlet.http.*;
013:
014: /**
015: *
016: * @version
017: */
018: public class HelloWebServlet extends HttpServlet {
019:
020: /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
021: * @param request servlet request
022: * @param response servlet response
023: */
024: protected void processRequest(HttpServletRequest request,
025: HttpServletResponse response) throws ServletException,
026: IOException {
027: response.setContentType("text/html;charset=UTF-8");
028: PrintWriter out = response.getWriter();
029:
030: out.println("<html>");
031: out.println("<head>");
032: out.println("<title>Servlet HelloWebServlet</title>");
033: out.println("</head>");
034: out.println("<body>");
035: out.println("<p>Enter your name:");
036: out.println("<form method=\"get\">");
037: out.println("<input type=\"text\" name=\"name\" size=\"25\">");
038: out.println("<br>");
039: out.println("<p>");
040: out.println("<input type=\"submit\" value=\"Submit\">");
041: out.println("</form>");
042: String name = request.getParameter("name");
043: if (name != null) {
044: try {
045: out.println(getHelloServiceSEIPort().sayHello(name));
046: } catch (java.rmi.RemoteException ex) {
047: out.println("<p>Caught an exception <p>" + ex);
048: }
049: }
050: out.println("</body>");
051: out.println("</html>");
052:
053: out.close();
054: }
055:
056: // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
057: /** Handles the HTTP <code>GET</code> method.
058: * @param request servlet request
059: * @param response servlet response
060: */
061: protected void doGet(HttpServletRequest request,
062: HttpServletResponse response) throws ServletException,
063: IOException {
064: processRequest(request, response);
065: }
066:
067: /** Handles the HTTP <code>POST</code> method.
068: * @param request servlet request
069: * @param response servlet response
070: */
071: protected void doPost(HttpServletRequest request,
072: HttpServletResponse response) throws ServletException,
073: IOException {
074: processRequest(request, response);
075: }
076:
077: /** Returns a short description of the servlet.
078: */
079: public String getServletInfo() {
080: return "Short description";
081: }
082:
083: // </editor-fold>
084:
085: private helloweb.HelloService getHelloService() {
086: helloweb.HelloService helloService = null;
087: try {
088: javax.naming.InitialContext ic = new javax.naming.InitialContext();
089: helloService = (helloweb.HelloService) ic
090: .lookup("java:comp/env/service/HelloService");
091: } catch (javax.naming.NamingException ex) {
092: // TODO handle JNDI naming exception
093: }
094: return helloService;
095: }
096:
097: private helloweb.HelloServiceSEI getHelloServiceSEIPort() {
098: helloweb.HelloServiceSEI helloServiceSEIPort = null;
099: try {
100: helloServiceSEIPort = getHelloService()
101: .getHelloServiceSEIPort();
102: } catch (javax.xml.rpc.ServiceException ex) {
103: // TODO handle service exception
104: }
105: return helloServiceSEIPort;
106: }
107: }
|