1 Reply Latest reply on Sep 13, 2005 4:40 AM by R B

    JSP/Servlet .war/.ear example needed.

    R B Newbie

      Can someone plz post a simple HelloWorld example where a JSP page links to a Servlet?

      JSP page is always found. Clicking on the Servet link from within the JSP page yields nothing.

      I'm having a tough time getting the Servlet to work.

        • 1. Re: JSP/Servlet .war/.ear example needed.
          R B Newbie

          managed to figure this out. Included below is a simple example that you can try out yourself:

          Simple example to create a JSP page calling a Servlet and deploy the .war (or .ear) in JBoss

          1) create the foll directory structure:


          2) store the files as follows

          JSP File: /example2/index.jsp
          Servlet File: /example2/WEB-INF/classes/HelloWorld.class
          (compile the servet HelloWorld.java and store the class file)
          web.xml: /example2/WEB-INF/web.xml
          application.xml: /META-INF/application.xml

          3) In JSP file, reference the Servlet as:

          <a href="/example2/Servlet/HelloWorld/>

          4) web.xml file

          <?xml version="1.0" encoding="ISO-8859-1"?>
          <!DOCTYPE web-app
          PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

          5) application.xml file

          <?xml version="1.0" encoding="ISO-8859-1"?>
          <display-name>Example 2</display-name>

          6) Create a .war file with the *contents* of example2 folder:

          cd c:\example2
          jar -cvf example2.war *

          (Same thing can be done using winzip, but **enter example2 directory** and zip the contents to example2.war)

          7) jar /META-INF/ + example2.war = example2.ear

          8) Deploy example2.ear in /server/default/deploy directory OR skip #7 and deploy the example2.war directly into the deploy directory

          http://localhost:8080/example2/index.jsp ---> JSP page
          http://localhost:8080/example2/servlet/HelloWorld ------> Servlet

          Note to access URLs:

          The URL to access the JSP page will be:

          To access the Servlet, simply append the <url-pattern> defined for the Servlet like this:

          Deploying the .ear file instead of the .war has no bearing on the URLS.