4 Replies Latest reply on Oct 27, 2008 11:27 AM by Peter Johnson

    Servlet Deployment Issue

    R Vince Newbie

      I package up a file, gg.war, as follows: (note, the same directory structure I have running in Tomcat 5x with no problems)

      MANIFEST.MF (in META-INF\ )
      IsItWorking.class ( in WEB-INF\classes\ )
      web.xml (in WEB-INF\ )

      My web.xml appears as follows:

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4">

      <servlet-name>IsItWorking</servlet-name>
      <servlet-class>IsItWorking</servlet-class>

      <servlet-mapping>
      <servlet-name>IsItWorking</servlet-name>
      <url-pattern>/gg/servlets</url-pattern>
      </servlet-mapping>
      </web-app>

      When I put this gg.war into my deployment directory, JBoss seems to correctly deploy it as:
      21:14:27,615 INFO [TomcatDeployer] deploy, ctxPath=/gg, warUrl=.../tmp/deploy/tmp30484gg-exp.war/

      (though, I do not see a directory called /gg anywhere where this thing should be unpacked to!)

      However, when I go to call this servlet:

      http://localhost:8080/gg/servlets/IsItWorking

      I get a 404 error (The requested resource (/gg/servlets/IsItWorking/IsItWorking) is not available.)

      Why can't see the results of this servlet, which works fine in Tomcat (I am using JBoss 4.2.3.GA). My servlet source code is simply:

      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.Date;
      import javax.servlet.*;
      import javax.servlet.http.*;

      public class IsItWorking extends HttpServlet
      {

      public void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
      throws ServletException, IOException
      {
      httpservletresponse.setContentType("text/html");
      PrintWriter printwriter = httpservletresponse.getWriter();
      String s = getServletConfig().getServletContext().getServerInfo();
      printwriter.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"> Yes, It's working! <META NAME=\"Author\" CONTENT=\"" + s + "\">" + "" + "<BODY BGCOLOR=\"#FFFFFF\">" + " " + " <IMG " + "ALT=\"[ Picture broken ? Access this from localhost ]\" " + "SRC=\"/jserv/status?image\" BORDER=\"0\">" + " <H1>" + "Yes, It's working!" + "</H1>" + " <H2>Congratulations, " + s + " is working!</H2>" + " <H3>[ local time is " + new Date() + " ]</H3>" + " <FONT SIZE=\"-1\">Copyright (c) 1997-99" + " <A HREF=\"http://java.apache.org/\">The Java Apache Project" + " All rights reserved." + " " + "" + "");
      }

      public IsItWorking()
      {
      }

      public static final String TITLE = "Yes, It's working!";


      As stated, this works fine when installed on Tomcat (4 and 5) but for whatever reason, I can;t make it fly in JBoss. Please help this newbie -- I've been at this for a few hours and can;t seem to get past this. Thanks!

        • 1. Re: Servlet Deployment Issue
          jaikiran pai Master

           

          <servlet-mapping>
          <servlet-name>IsItWorking</servlet-name>
          <url-pattern>/gg/servlets</url-pattern>
          </servlet-mapping>


          So shouldn't you just be using http://localhost:8080/gg/servlets instead of http://localhost:8080/gg/servlets/IsItWorking in the browser?

          • 2. Re: Servlet Deployment Issue
            R Vince Newbie

            When I try that URL, I get the same 440 error:

            The requested resource (/gg/servlets/) is not available.

            When it deploys, shouldn;t it unpack the war somewhere (I see it unpacks things to:

            G:\jboss-4.2.3.GA\server\default\tmp\deploy\tmp30485gg-exp.war

            but shouldn;t it unpack it all under:

            G:\jboss-4.2.3.GA\server\default\deploy ?

            Lastly, if put a standard html page at the root level of my war, I can access it after deploying with:

            http://localhost:8080/gg/index.html

            but not the servlet. I must be doing something stupid - I'm not the first guy to try to deploy a simple servlet on JBoss -- it has to be something I am missing that is right in front of my eyes in terms of how I have things configured -- but I cannot seem to find it.

            • 3. Re: Servlet Deployment Issue
              R Vince Newbie

              Restarted the server, it redoployed on startup, and runs fine now. Hmmmm.

              • 4. Re: Servlet Deployment Issue
                Peter Johnson Master

                One other thing to consider - some web app containers have issues with deploying servlets that do not have a package name. Assigning a package name will help. I recall having a discussion about this in this forum quite some time ago with the solution being to add a package. Example:

                Add this to the servlet's source:

                package foo;
                // rest of servlet source as you posted


                Change servlet stanza in the web.xml to:

                <servlet>
                 <servlet-name>IsItWorking</servlet-name>
                 <servlet-class>foo.IsItWorking</servlet-class>
                 </servlet>


                Change your ww.war to contain:

                WEB-INF/web.xml
                WEB-INF/classes/foo/IsItWorking.class