Eclipse Web Apps Practical
Conestoga College ©  Peter Komisar


Let's assume as basic building blocks we will
want to use HTML pages, servlets and Java
Server Pages as the elements of our web application.
Lets confirm we can build all of these in Eclipse
using the following recipes.

HTML

1 ) Open a New Web Project.
2) This will become an invitation to open an Enterprise Project.
3) Do it.
4) Name it.
5) Go to File -> New --> Other --> Web --> HTML
6) Put the HTML under the  ProjectName \ WebContent

// Note under Run --> Run Configurations
// Controls for Server environments

7) Try and Run from Eclipse. Select a Server.
( I had to go under Window --> Web Browser
and make the System browser the default. )

8) If this doesn't work, try opening on the location
by booting the browser externally on the site. \

Servlets

Servlets need the Servlet API in order to compile.
Let us say we also which to use the famous web
server Apache. You can point Eclipse to the jar
files found in Apache if you wish so Eclipse can
find them.

1) Right Click on the Web Project You have created.
Click on Properties, go to Java Build Path. Use
'Add External Jars' to put the Servlet API Jars into
the Path.

The packages you need for the servlet API are
the following.


Java Servlet API Jars

Creating a New Servlet in Eclipse


1. Open Eclipse
2. Go to File -> New --> Other --> Web --> Servlet
3. Carefully transfer the contents of HelloServlet
    to the newly created template.
4. Save
5. Run

// Caution: On my machine in order to use Apache I have to
// stop the default server that starts with
the Sun J2EE installation

6. Select Server to Start
7. Results should show in the browser inside Eclipse


JSPs


Java Server pages need the same libraries that we
imported for the Servlet class.


Creating a New JSP Page With Eclipse

Creating JSPs are similar to Servlets however, the
reference is from inside the HTML of a JSP page
rather than from a Servlet.

1. Open Eclipse
2. Go to File -> New --> Other --> Web --> JSP

3. In the template add some content. Here is some
Java code dressed up in the syntax of a JSP which
you can add.


Snippet to Add to the JSP

<H1>Today is!  </H1>
<HR/>
<%!
    String s=Calendar.getInstance().getTime().toString();
    %>
<%=
    s.toUpperCase()
    %>

4. Save
5. Run

You should appreciate that the Eclipse environment is
doing a good deal of 'library service' for us in keeping
the code in the appropriate directories. As well, (if you
get it working!) the environment also makes it easy to
develop the various web components needed to make
a J2EE application.