Getting Started with J2EE

When starting a new application or development environment, first build the proverbial “Hello World” example. This step is instructional when working with J2EE, as it was for JSP in Chapter 13.

“Hello World” in J2EE

Start by building the simplest of all possible web applications: a “Hello World” JSP file. You created a similar JSP in the last chapter, but deploying a JSP as part of a J2EE application is different from deploying a JSP as a simpler web application. You will get a feel for these differences by working through these basic steps.

Create a file called index.jsp, with the contents shown in Example 14-1.

Example 14-1. A Hello World JSP

<HTML>
    <HEAD>
        <TITLE>Test</TITLE>
    </HEAD>
    <BODY>
    Hello World!<BR>
    <%= new java.util.Date().toString(  ) %>
    </BODY>
</HTML>

To deploy this file, create a WAR file. A WAR is just a ZIP file with a specific encoding, and in this case you can get away with not creating a web.xml file or any other supporting configuration or property files. Copy the index.jsp file to the /usr/local/jboss/server/default/deploy directory, and then issue the following command:

[Localhost:~/Documents] wiverson% ls index.jsp
index.jsp

[Localhost:~/Documents] wiverson% zip test.war index.jsp
  adding: index.jsp (deflated 19%)

[Localhost:~/Documents] wiverson% mv test.war /usr/local/jboss/server/default/deploy/

[Localhost:~/Documents] wiverson%

This command creates the needed WAR file and places it in JBoss’s deployment directory (/usr/local/jboss/server/default/deploy ...

Get Mac OS X for Java Geeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.