Skip to content

Creating a Java Web App

Making it real.

A Java Web Application

  • A web app is just a directory. (What? That’s it?)

    java112/
    |-- declarations2.jsp
    |-- declarations.jsp
    |-- default.css
    |-- expressions.jsp
    |-- firstJSP.jsp
    |-- images/
    |   |-- img1.jpg
    |   |-- img2.jpg
    |   |-- img3.jpg
    |   |-- img4.jpg
    |   |-- img5.jpg
    |   `-- Thumbs.db
    |-- index.jsp
    |-- jspInit.jsp
    |-- linkingDemo.html
    |-- META-INF/
    |   `-- MANIFEST.MF
    |-- myFirstJSP.jsp
    |-- scriptlets.jsp
    `-- WEB-INF/
        |-- classes/
        |   `-- java112/
        |       `-- project2/
        |           |-- SimpleHtmlServlet.class
        |           |-- SimpleTextServlet.class
        |           |-- TestHTTPServer.class
        |           `-- TrivialServlet.class
        |-- lib/
        `-- web.xml
    
  • However, the directory has to be structured just right. (I knew there was a catch.)

  • Here are some of the elements that are required.

    • A WEB-INF/ directory.
    • A classes/ in the WEB-INF directory.
    • A web.xml file in the WEB-INF directory.
    • A META-INF/ directory.
    • A MANIFEST.MF file in the META-INF directory.
    • All the static files for your site.
    • A lib/ directory to contain jar files your app needs.
  • Then the entire directory is zipped into a file and named java112.war instead of java112.zip.

  • Then we have to move the file to your tomcat/webapps/ directory.
    • $ ant deploy will do all of this for you.

Accessing your Web App