Title: CSCI 6962: Serverside Development and Programming
1CSCI 6962 Server-side Development and Programming
- Lecture 2 The Jakarta Tomcat Web Container and
the NetBeans IDE
2Client-Server Web Architecture
- Client browser sends request for page to server
- Server sends response page and sends to client
Client
Browser
Response containing Syllabus.htm as a long string
(lthtmlgtltheadgtlttitlegtCSCI 6962 Syllabuslt/titlegtlt/he
adgtltbodygt)
www.cis.ysu.edu/john/Syllabus.htm
port
Request to www.cis.ysu.edu for Syllabus.htm
Server john public_html Syllabus.htm
3Form Handling
- Server must
- Listen on port for requests
- Parse request to determine values of parameters
- Generate appropriate response page based on
parameter values - Send response page back to client
4Simple perl cgi-bin Program
- !/opt/local/bin/perl
- program to print back results of test form
- parse input string into an associative list
- _at_pairssplit(//, ENV'QUERY_STRING')
- foreach pair (_at_pairs)
- _at_itemsplit(//, pair)
- key_at_item0
- value_at_item1
- formdatakeyvalue
-
- print response to form
- print "Content-type text/html\n\n"
- print "ltHTMLgtltHEADgtltTITLEgtcgi-bin
responselt/TITLEgtltBODYgt" - print "Thank you for your order of "
- print formdata"quantity"
- print " widgets!"
- print "lt/BODYgtlt/HTMLgt"
5Web Containers
- Program running continuously on server
- Runs code to handle requests
- Built-in methods for parsing requests, generating
responses - Handles other important functions
- Session tracking
- Database access
- Email generation
- Security and encryption
6Web Containers
- Jakarta Tomcat
- Written in Java
- NetBeans IDE
- Acts as engine for Java Server Pages and servlets
- Microsoft IIS
- Visual Basic/Visual C/C
- Active Server Pages
7Downloading the Java SDK
8Downloading the Java SDK
9Downloading the Java SDK
10The NetBeans IDE
- Integrated Development Environment for Java
Programming - Editing code (with hints)
- Compiling code
- Running code
- Good for JSP/servlet development
- Allows easy development of web applications
- Has own version of Tomcat for testing
- Automatically interacts with external Tomcat
- No need to manipulate Tomcat file structure
11Downloading NetBeans
12Downloading NetBeans
13Downloading NetBeans
- Note NetBeans has built-in Tomcat server
14Creating a Web Application
- In NetBeans File ? New Project
- Choose Web and Web Application
15Creating a Web Application
- Give your project a name (I called this one
WidgetSite) - Give it a location (I have put it in a directory
called 6962) - Make sure it is set as the Main Project
16Creating a Web Application
- The final page shows information (such as which
server this project uses) - Can change to external server if desired
17Creating a Web Application
NetBeans creates an initial web site
Structure shown in the project window
Creates an initial index.jsp page (default home
page of the new site)
The index.jsp is initially just a Hello world
page
18Running a Web Application
- Running the site opens the index.jsp page
- Can choose browser (and should test with all!)
19Building a Web Application
- Modify and add files to create web site
index.jsp Prompts user for number of widgets
reciept.jsp Displays number of widgets purchased
20Building a Web Application
21Adding a JSP
Choose a JSP
Give it a name
22Running the Site
Compiles and runs current webapp (starting Tomcat
and opening browser)
23Installing Tomcat
- Detailed Instructions in Chapter 2 (page 31)
- Copy JAR files from Tomcat to Java Runtime
Environment - Necessary for JSPs and servlets to compile
24Installing Tomcat
- Tell Tomcat where to look for Java (page 34)
- Edit catalina.bat file in bin directory of Tomcat
25Installing Tomcat
- Add user in management role (page 50)
- Edit tomcat-users.xml file in conf directory of
Tomcat
26Testing Tomcat
- Start Tomcat
- Execute startup.bat in bin directory
27Testing Tomcat
- This will open Tomcat control window
- Note Should not have NetBeans and Tomcat running
simultaneously (both try to use same port)
28Testing Tomcat
- Tomcat is now listening for requests!
- Listening at port 8080 by default
- Test enter http//localhost8080/ in your browser
29Tomcat Structure
- Listens on port 8080 for requests
- Retrieves page requested
- Must be part of its file structure in webapps
directory - Example http//localhost8080/
- Sends request to this machine for index.html file
in ROOT subdirectory of webapps
30Tomcat Structure
- Another example http//localhost8080/examples/js
p/simpletag/foo.jsp
31Tomcat Structure
- Side point JSPs/servlets can display messages
in Tomcat window (often used for diagnostics)
32Tomcat Structure
- Meaning of this URLhttp//localhost8080/example
s/jsp/simpletag/foo.jsp
Invoke server listening on port 8080 of this
machine
Access this file in this subdirectory of the
tomcat/webapps directory
33Tomcat Structure
- Side note Usually refer to server on another
machine http//www.cis.ysu.edu/examples/jsp/simple
tag/foo.jsp - For testing, often run client and server on same
machine
Invoke server at this remote URL
Access this file in this subdirectory of the
tomcat/webapps directory
Port 8080
request
Tomcat
response
Browser
request
http//localhost8080/...
response
34Tomcat Structure
- If requested page is server page/servlet,
executes code embedded in page to generate
corresponding html page - Final html page sent as response
35Adding a Tomcat Server
36Adding a Tomcat Server
- Select Tomcat 6.0
- Give it a name otherthan Tomcat 6.0
37Adding a Tomcat Server
- Enter the directorywhere you installed Tomcat
- Enter a name and a password for amanager
role(we will use thismore later)
38Adding a Tomcat Server
- By default, Tomcat listens at port 8080
39Adding a Tomcat Server
- Change server used by your webapp
- File ? Project Properties
- Choose Run propertiesand select the external
server
40Deploying your Site to Tomcat
- Right-click project and choose Deploy
- This copies all web site files into build\web
subdirectory
41Deploying your Site to Tomcat
- Copy these files into a subdirectory of webapps
in Tomcat
42Deploying your Site to Tomcat
- Start Tomcat (after closing NetBeans)
- Go to http//localhost8080/WidgetSite in browser