2 Replies Latest reply on Aug 29, 2009 8:51 PM by peterj

    Deploying Simple Servlet

    dontocsata

      Hello all, I am new to Java Enterprise, Servlets, and JBoss (learning for a job).

      I jave jboss 4.2.3, running up fine.

      I have a simple HelloWorld Servlet (code below). How do I deploy this on jBoss? I made a folder WEB-INF with a web.xml containing:

      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
       <servlet>
       <servlet-name>hello</servlet-name>
       <servlet-class>test.HelloServlet</servlet-class>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>hello</servlet-name>
       <url-pattern>/hello</url-pattern>
       </servlet-mapping>
      </web-app>


      I put my web-inf folder into the deploy folder and it fails to deploy it, it says the state for each file is 'INIT_WAITING_DEPLOYER'.

      How do I actually get this servlet to run?

      Folder Structure:
      WEB-INF/web.xml
      WEB-INF/classes/test/HelloServlet.class

      CODE:
      package test;
      
      import java.io.*;
      
      import javax.servlet.http.*;
      import javax.servlet.*;
      
      public class HelloServlet extends HttpServlet {
       public void doGet (HttpServletRequest req,
       HttpServletResponse res)
       throws ServletException, IOException
       {
       PrintWriter out = res.getWriter();
      
       out.println("Hello, world!");
       out.close();
       }
      }
      


        • 1. Re: Deploying Simple Servlet
          dontocsata

          I got it to deploy, but how do I access it?

          I made the following changes:

          File structure:
          helloworld.war/WEB-INF/web.xml
          helloworld.war/WEB-INF/classes/test/HelloServlet.class

          XML File:

           <!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 xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
           <servlet>
           <servlet-name>hello</servlet-name>
           <servlet-class>test.HelloServlet</servlet-class>
           </servlet>
          
           <servlet-mapping>
           <servlet-name>hello</servlet-name>
           <url-pattern>/hello</url-pattern>
           </servlet-mapping>
          </web-app>
          


          • 2. Re: Deploying Simple Servlet
            peterj

            http://localhost:8080/helloworld/hello

            The "/helloworld" context comes from the WAR file name, the "/hello" comes from the url-pattern in the web.xml.