First Web application – JSP and java Servlet

How to create your first HTML Web application:

  • File -> New Project
  • Under Web, select: Dynamic Web project
  • Give it a project name and assign Tomcat as the server.
  • Set your source folder to: src\java\main
  • Set the content directory to: WebContent and ensure the web.xml creation is selected.
  • Click finish.

Make sure your "Servers" project is open.

  • Select your Service project and open it.
  • It will contain something like: Apache Tomcat v6.0-config

Adding your first JSP page.

  • Right click inside the WebContent.
  • Click File -> new
  • Name your JSP index.jsp (the acceptable defaults are in the web.xml file)

Here is a sample JSP: index.jsp (521.00 bytes) (Right click and save, it will execute when clicked).

Running the project.

  • Right click inside the project.
  • Click Run As -> Run on server.
  • Make sure your Web is site is in the Configured column.
  • Click Finish
  • After the application loads, the web.xml will contain the newly added JSP page.
  • Test the JSP by adding http://localhost:8080/%Application%/ in your browser address bar.

Adding your first Servlet page.

  • Right click inside the Project or 'Java resources'.
  • Click New -> Servlet
  • Give your package and Class name.
  • The resulting Servlet will be placed in folder: Java Resources
  • Two words of caution:
    • The servlets are case sensitive.
    • A restart of Tomcat must occur after adding a new servlet.

Code to your Web Application.

  • Right click inside the Project or 'Java resources'.
  • Click New -> Class
  • Give your package and Class name.
  • The resulting Servlet will be placed in folder: Java Resources