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

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

    Will Senn Newbie

      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



      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:

      note: you might have to set the classpath for the servlet.jar, ie. set
      before calling ant if it complains.

      4. Should have had no errors and created a build directory with the structure:

      5. To deploy the Web Application on Tomcat, simply copy the file:
      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

      6. To test the deployment of the JSP browse to:

      7. To test the deployment of the Servlet, browse to:
      and click the hyperlink:
      Click here to execute the Servlet

      or browse to:

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


      <!-- 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 -->


      <?xml version="1.0" encoding="ISO-8859-1"?>

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



      <?xml version="1.0" encoding="ISO-8859-1"?>

      <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"


      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
      PrintWriter out = response.getWriter();

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


      <%@page language="java" %>

      Deployment Example

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


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

          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:




          Then in index.jsp, I changed this line:
          Click here.../a>
          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/