1 Reply Latest reply on Dec 2, 2002 7:02 PM by decuser

    Help: Example JSP/Servlet works Jetty not Tomcat

    decuser

      JBoss Elite!

      I have tried any number of ways to get the JBoss-3.0.4/Tomcat
      4.1.12-LE-jdk14 Integrated bundle to serve up a simple jsp/servlet web
      application. Each of the approaches has been unsuccessful. The deployed
      JSP works, but the called servlet does not. I have successfully taken
      the example.war file and copied it into my standalone tomcat and it
      worked. I have installed the JBoss-3.0.4 with JBossWeb (Jetty) and
      deployed the example.war and had it work. Could someone please take a
      look at my steps and tell me what I did
      wrong? I tried to attach the example.war in the forum - didn't work...

      Thanks,

      Will


      Here's the readme that I created...

      1. Create the following 4 directories wherever you like:
      1. example
      2. example\src
      3. example\web
      4. example\descriptors

      2. Cut and paste the contents of the following 5 files saving them in the
      appropriate directories - the content is at the bottom of this file:
      1. example\build.xml
      2. example\descriptors\application.xml
      3. example\descriptors\web.xml
      4. example\src\HelloWorld.java
      5. example\web\index.jsp

      3. Open a command prompt in the example directory and type:
      ant

      note: you might have to set the classpath for the servlet.jar, ie. set
      classpath=D:\jboss-3.0.4\tomcat-4.1.x\common\lib\servlet.jar
      before calling ant if it complains.

      4. Should have had no errors and created a build directory with the structure:
      build\deploy
      build\descriptors
      build\ear
      build\ear\META-INF
      build\src
      build\war
      build\war\WEB-INF
      build\war\WEB-INF\classes

      5. To deploy the Web Application on Tomcat, simply copy the file:
      build\deploy\example.war
      into the %TOMCAT_HOME%\webapps directory

      5a. To deploy the Web Application on JBoss, simply copy the file:
      build\deploy\example.war into the jboss-3.0.4\server\default\deploy
      directory.

      6. To test the deployment of the JSP browse to:
      http://localhost:8080/example/index.jsp

      7. To test the deployment of the Servlet, browse to:
      http://localhost:8080/example/index.jsp
      and click the hyperlink:
      Click here to execute the Servlet

      or browse to:
      http://localhost:8080/example/servlet/HelloWorld

      8. Good job and well done! (Cry if it's JBoss + Tomcat)

      example\build.xml
      -------------------snip

















      <!-- Create build/src directory to hold the output classes-->


      <!-- Create build/src directory to hold the output classes-->


      <!-- Create build/deploy directory to hold the output war and ear files-->


      <!-- Create Web-inf and classes directories -->



      <!-- Create Meta-inf and classes directories -->


      <!-- Copy the application.xml and web.xml files from descriptors
      to build/descriptors -->





      <!-- Main target -->


      <!-- Compile Java Files and store in /build/src directory -->




      <!-- Create the War File -->











      <!-- Create war file and place in ear directory -->


      <!-- Copy the war file to the deploy directory -->





      <!-- Create the War File -->





      <!-- Create ear file and place in ear directory -->



      -------------------snip


      example\descriptors\application.xml
      -------------------snip
      <?xml version="1.0" encoding="ISO-8859-1"?>


      <display-name>Example Application</display-name>


      <web-uri>example.war</web-uri>
      <context-root>/example</context-root>



      -------------------snip


      example\descriptors\web.xml
      -------------------snip
      <?xml version="1.0" encoding="ISO-8859-1"?>

      <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

      <web-app>
      </web-app>
      -------------------snip


      example\src\HelloWorld.java
      -------------------snip
      import java.io.*;
      import java.text.*;
      import java.util.*;
      import javax.servlet.*;
      import javax.servlet.http.*;

      public class HelloWorld extends HttpServlet {


      public void service(HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException
      {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println("");
      out.println("");
      out.println("Deployment Example Servlet!");
      out.println("");
      out.println("");
      out.println("<H1>Hello World!</H1>");
      out.println("<a href=\"javascript:history.back()\">Click here to return to the JSP");
      out.println("");
      out.println("");

      }
      }
      -------------------snip


      example\web\index.jsp
      -------------------snip
      <%@page language="java" %>



      Deployment Example



      <H1>Deployment Example</H1>
      The deployment of the JSP worked!
      Click here to execute the Servlet


      -------------------snip