4 Replies Latest reply on Oct 28, 2002 5:51 PM by Bob Sturim

    Help with deploying a servlet

    Bob Sturim Newbie

      I've taken the standard template example and attempted to extend it with a simple servlet. My war file has the following contents:

      C:\java\dev\jbosstest\build\deploy>jar -tf web-client.war
      META-INF/
      META-INF/MANIFEST.MF
      index.jsp
      WEB-INF/
      WEB-INF/lib/
      WEB-INF/classes/
      WEB-INF/classes/org/
      WEB-INF/classes/org/sturim/
      WEB-INF/classes/org/sturim/edb/
      WEB-INF/classes/org/sturim/edb/common/
      WEB-INF/classes/org/sturim/edb/common/interfaces/
      WEB-INF/classes/test/
      WEB-INF/classes/test/interfaces/
      WEB-INF/classes/test/interfaces/AbstractData.class
      WEB-INF/classes/test/interfaces/InvalidValueException.class
      WEB-INF/classes/test/interfaces/SequenceGenerator.class
      WEB-INF/classes/test/interfaces/SequenceGeneratorHome.class
      WEB-INF/classes/test/interfaces/ServiceUnavailableException.class
      WEB-INF/classes/test/interfaces/TestBMPEntity.class
      WEB-INF/classes/test/interfaces/TestBMPEntityData.class
      WEB-INF/classes/test/interfaces/TestBMPEntityHome.class
      WEB-INF/classes/test/interfaces/TestBMPEntityPK.class
      WEB-INF/classes/test/interfaces/TestEntity.class
      WEB-INF/classes/test/interfaces/TestEntityData.class
      WEB-INF/classes/test/interfaces/TestEntityHome.class
      WEB-INF/classes/test/interfaces/TestEntityPK.class
      WEB-INF/classes/test/interfaces/TestSession.class
      WEB-INF/classes/test/interfaces/TestSessionHome.class
      WEB-INF/classes/org/sturim/Test.class
      WEB-INF/jboss-web.xml
      WEB-INF/web.xml

      My servlet is contained in the WEB-INF/classes/org/sturim/Test.class entry.

      The only change I've made to the original template code is to add a very simple servlet (that does nothing except print a message) called org.sturim.Test. I've added the servlet to the web.xml file as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE web-app PUBLIC
      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">

      <web-app>

      <display-name>Web Client</display-name>

      <servlet-name>Test</servlet-name>
      <servlet-class>org.sturim.Test</servlet-class>
      <load-on-startup>2000</load-on-startup>


      <!-- The Welcome File List -->
      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
      </welcome-file-list>

      <ejb-ref>
      <ejb-ref-name>ejb/webtest/TestSession</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      test.interfaces.TestSessionHome
      test.interfaces.TestSession
      </ejb-ref>

      </web-app>

      I can access the sample index.jsp file that was shipped as part of the original template code by typing:

      http://localhost:8080/web-client/index.jsp

      I know my servlet is deployed properly because I set it to load on startup, and I can see my debug message printed to the log.

      I get no errors when I deploy my web-client.war to %JBOSS_HOME%\server\default\deploy.

      But if I try to access my servlet such as:

      http://localhost:8080/web-client/Test, I get a 404 error. I get the same message if I get
      http://localhost:8080/web-client/servlet/Test.

      Any ideas would be greatly appreciated.

        • 1. Re: Help with deploying a servlet
          Bob Sturim Newbie

          After many hours of experimenting and searching the forums, I got a partial answer. If I add a servlet-mapping entry to my web.xml, such as:

          <servlet-mapping>
          <servlet-name>Test</servlet-name>
          <url-pattern>/test/*</url-pattern>
          </servlet-mapping>

          I could then successfully invoke the servlet. But I was never successful without the mapping entry (which isn't necessary when I run it under plan old Tomcat standalone).

          Anybody understand why it doesn't work without the servlet mapping?

          • 2. Re: Help with deploying a servlet
            Jay McGaffigan Newbie

            Where did you put your serlvet file within the template hierarchy?

            I am trying to do the same thing you are.

            For the template project we get a directory structure to:
            src
            -etc
            -main
            -client
            -ejb
            -servlet
            -web

            I've put my servlet in the servlet directory. When it compiles and builds the war file I get the following:
            META-INF/
            META-INF/MANIFEST.MF
            wines.jsp
            addTasting.html
            WEB-INF/
            wine/
            WEB-INF/jboss-web.xml
            wine/TastingServlet.class
            WEB-INF/classes/
            WEB-INF/classes/wine/
            WEB-INF/classes/wine/interfaces/
            WEB-INF/classes/wine/interfaces/WineEJBPK.class
            WEB-INF/classes/wine/interfaces/SequenceGeneratorHome.class
            WEB-INF/classes/wine/interfaces/SequenceGenerator.class
            WEB-INF/classes/wine/interfaces/WineEJBLocalHome.class
            WEB-INF/classes/wine/interfaces/WineEJBLocal.class
            WEB-INF/classes/wine/interfaces/WineEJBData.class
            WEB-INF/classes/wine/interfaces/TastingEJBPK.class
            WEB-INF/classes/wine/interfaces/TastingEJBLocalHome.class
            WEB-INF/classes/wine/interfaces/TastingEJBLocal.class
            WEB-INF/classes/wine/interfaces/TastingEJBData.class
            WEB-INF/classes/wine/interfaces/TasterEJBPK.class
            WEB-INF/classes/wine/interfaces/TasterEJBLocalHome.class
            WEB-INF/classes/wine/interfaces/TasterEJBLocal.class
            WEB-INF/classes/wine/interfaces/TasterEJBData.class
            WEB-INF/classes/wine/interfaces/ResultsEJBPK.class
            WEB-INF/classes/wine/interfaces/ResultsEJBLocalHome.class
            WEB-INF/classes/wine/interfaces/ResultsEJBLocal.class
            WEB-INF/classes/wine/interfaces/ResultsEJBData.class
            WEB-INF/web.xml

            my servlet is called TastingServlet and it's not within the "classes" subdirectories. Some posts I found on these forums lead me to believe that it needs to be. (I get a 503 error "Dynamic Serlvet not loaded from Context").

            So I am trying to decide if the compile-web or war tag is responsible for fixing this.

            Hopefully once I get this part figured out I'll be up and running but I suspect I might only get to the point you are at...

            Jay

            • 3. Re: Help with deploying a servlet
              Jay McGaffigan Newbie

              Well I actually got my servlet working... All I had to do was modify the build.xml file to put the compiled servlet into the WEB-INF/classes directory ( I changed the mkdir command below):
              <!-- =================================================================== -->
              <!-- Compiles the WEB source code -->
              <!-- =================================================================== -->












              --

              From this point on my app was recognizing the servlet no problem (I created an HTML page which has a form that submits to web-client/servlet/TastingServlet

              Hope this helps.

              As you can tell I didn't exactly add a servelt to the existing test code but I did add a new set of beans and such (basically I changed the names of everything).

              Jay

              • 4. Re: Help with deploying a servlet
                Bob Sturim Newbie

                I did put my servlet class under the WEB-INF/classes directory. You can see it in my original listing as

                WEB-INF/classes/org/sturim/Test.class

                But no, I still could not access it via a url without putting the servlet mapping there. I saw one other post from another forum that hinted at a similar issue.

                As part of your efforts, did you need to adjust the web.xml file?