Share this page 

Deploy a Servlet(this howto is deprecated)Tag(s): DEPRECATED


Here the simplest way to execute a servlet through Jaguar.
Note : this way you can't control the servlet through Jaguar manager.

1. Take the following Servlet :

import javax.servlet.*;
import javax.servlet.http.*;
public class MyHelloWorld extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    public void destroy() {
    }
   protected void processRequest
     (HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet</title>");
    out.println("</head>");
    out.println("<body><h1>My Hello World</H1>");

    out.println("</body>");
    out.println("</html>");
    out.close();
    }
   protected void doGet
      (HttpServletRequest request, HttpServletResponse response)
          throws ServletException, java.io.IOException {
    processRequest(request, response);
    }
   protected void doPost
      (HttpServletRequest request, HttpServletResponse response)
          throws ServletException, java.io.IOException {
    processRequest(request, response);
    }
   public String getServletInfo() {
    return "Hello world servlet";
    }
}
2. Compile as MyHelloWorld.class
3. Copy the class into %jaguar%\html\classes
4. in IE : http://localhost:8080/servlet/MyHelloWorld

Another way is to install the Servlet through Jaguar Manager
Note : this way you can have init parameters, give a nice name to the servlet, etc...

  1. same servlet
  2. compile
  3. Same copy
  4. In Jaguar Manager, Servlets -> new Servlet , give MyServletHelloWorld as the name, the fully qualified name is MyHelloWorld
  5. In Jaguar Manager, Jaguar -> Installed Servlets -> Install Servlet -> Intall an Existing Servlet , select MyServletHelloWorld
  6. On Installed Servlets, refresh with RMB (right mouse button)
  7. start MyServletHelloWorld servlet with the MRB (mouse right button)
  8. in IE : http://localhost:8080/servlet/MyServletHelloWorld

The best way to deploy a Servlet is to use a Web application defined in a WAR file. Habitually, you build the WAR file with your IDE (like Netbeans or Forté). Then you deploy the WAR file to Jaguar with the Jaguar Manager ( RMB on Web Application - Deploy). You have to stop/start Jaguar after the deployment because the Refresh seems to be broken.