Difference between revisions of "Hello Web with Tomcat"

From Progzoo
Jump to: navigation, search
(Run / Run on server)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Complete [[Hello World in Eclipse]] before starting this.
 
Complete [[Hello World in Eclipse]] before starting this.
 
==Download Tomcat==
 
==Download Tomcat==
[[Image:Eclipse_Tomcat_Download.png|thumb]]
+
[[Image:Eclipse_Tomcat_Download.png|Download Binary, Core|thumb]]
 
*Unzip it to somewhere convenient
 
*Unzip it to somewhere convenient
 
**for example '''C:\'''
 
**for example '''C:\'''
Line 14: Line 14:
 
<br clear=all>
 
<br clear=all>
 
==Run time environment==
 
==Run time environment==
[[Image:Eclipse_New_Dynamic.png|thumb]]
+
[[Image:Eclipse_New_Dynamic.png|Create a new project|thumb]]
 
*You need to specify the '''Project name''' and the '''Target runtime'''
 
*You need to specify the '''Project name''' and the '''Target runtime'''
 
*Name your project '''HelloWeb'''
 
*Name your project '''HelloWeb'''
Line 35: Line 35:
 
*The servlet should have a capital letter
 
*The servlet should have a capital letter
 
*'''HelloWeb''' is fine
 
*'''HelloWeb''' is fine
 +
<br clear=all>
 +
==New Servlet Options==
 +
[[Image:Eclipse_New_Servlet_Options.png|You only need the doGet|thumb]]
 +
*You can accept the default options
 +
*You will only be changing '''doGet'''
 +
<br clear=all>
 +
==Firewall Problems==
 +
[[Image:Eclipse_Firewall_Problems.png|Your firewall may complain|thumb]]
 +
*You may have an issue with your firewall
 +
*You need the firewall to allow a listener on port 8080
 +
**You only need local access at the moment
 +
**You can allow access from 127.0.0.1 to port 8080
 +
*Avoid port 80 (as you may find other processes competing for this one)
 +
*You can use a different port if you have something else using 8080
 +
<br clear=all>
 +
==Change doGet==
 +
[[Image:Eclipse_Change_doGet.png|Change the method doGet|thumb]]
 +
*Your code will run in '''doGet'''
 +
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 +
  response.getWriter().println("Hello World");
 +
}
 +
*The stub is created by Eclipse - you can change the bit inside this method.
 +
<br clear=all>
 +
==Run / Run on server==
 +
[[Image:Eclipse_Run_on_server.png|Right Click to Run on Server|thumb]]
 +
*You can run on the server
 +
*The output will show up in the crummy Eclipse browser
 +
**Look in '''Window / Web Browser''' to change this

Latest revision as of 03:18, 16 November 2013

Complete Hello World in Eclipse before starting this.

Download Tomcat

Download Binary, Core
  • Unzip it to somewhere convenient
    • for example C:\
  • No need to install anything - Eclipse will take care of it
    • You just need to point Eclipse to the file location and it will take care of the installation
    • If you need to run tomcat outside Eclipse you will need to read some documentation


From Eclipse, start a new project

Eclipse New Project Dynamic Web.png
  • File / Project / Web / Dynamic Web Project


Run time environment

Create a new project
  • You need to specify the Project name and the Target runtime
  • Name your project HelloWeb
  • Click New Runtime


New Runtime

Make this match the downloaded version
  • Choose the runtime that matches the version you downloaded (7.0)
  • In the next step you specify the folder


Specify the folder

Where did you put tomcat?
  • Specify the directory where you unzipped tomcat
  • Accept the defaults regarding perspective


New Servlet

File New Servlet
  • You have a new project - now create a servlet
  • The servlet should have a capital letter
  • HelloWeb is fine


New Servlet Options

You only need the doGet
  • You can accept the default options
  • You will only be changing doGet


Firewall Problems

Your firewall may complain
  • You may have an issue with your firewall
  • You need the firewall to allow a listener on port 8080
    • You only need local access at the moment
    • You can allow access from 127.0.0.1 to port 8080
  • Avoid port 80 (as you may find other processes competing for this one)
  • You can use a different port if you have something else using 8080


Change doGet

Change the method doGet
  • Your code will run in doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.getWriter().println("Hello World");
}
  • The stub is created by Eclipse - you can change the bit inside this method.


Run / Run on server

Right Click to Run on Server
  • You can run on the server
  • The output will show up in the crummy Eclipse browser
    • Look in Window / Web Browser to change this