2 Replies Latest reply on Dec 23, 2002 1:59 PM by bryanlewis

    FAQ:Servlet Deployment Help - Works with JBoss+Jetty not wit

    decuser

      This is a very frequently asked question that no one seems willing/able to adequately explain...

      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 the included .war file (look at 1st reply) and my steps and tell me what I did
      wrong?

      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

        • 1. Re: FAQ:Servlet Deployment Help - Works with JBoss+Jetty not
          decuser

          Here's the war and text

          • 2. Re: FAQ:Servlet Deployment Help - Works with JBoss+Jetty not
            bryanlewis

            This question is a couple of weeks old and might've already been figured out. I just now came across it while I was trying the latest JBoss+Tomcat, so I tried deploying the example. Here's what worked for me.

            I added a servlet-mapping to web.xml to make sure JBoss knew where to find the servlet class. That file now looks like:

            <web-app>

            <servlet-name>HelloWorld</servlet-name>
            <servlet-class>HelloWorld</servlet-class>

            <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/HelloWorld</url-pattern>
            </servlet-mapping>
            </web-app>

            Then in index.jsp, I changed this line:
            Click here.../a>
            to:
            Click here...

            An absolute reference "/example/HelloWorld" worked too.

            Recreated the war, deployed, and it worked. I was able to click back and forth between the JSP and the servlet.

            I don't know exactly why the original example worked in plain Tomcat ... haven't tried it there... but Tomcat might've had a configuration directive that took care of the "/servlet" mapping for you. It reminds me of the comment, "Other app servers (JRun and tomcat) were covering my error. Jboss will keep you honest." in the post http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/