Enterprise Java Logo

Getting Started with Web Applications

by Dr. Wenjie He

Introduction to Web Applications

What is a web applcation?

A web application is an application that is accessed via web browser over a network. Server-side technologies, such as Java EE, Microsoft .NET, and PHP, are used to provide dynamic functionalities for a web application. A database is usually necessary to provide data storage for a mission-critical web application.

In this class, we only focus on the Java-based web technologies. From now on, when we mention web applications, we mean those web applications that use the Java-based web technologies.

Three-tier architecture

Technologies used in three-tier architecture

Tier Technologies
Presentation HTML/XHTML, CSS, etc.
Business logic Servlets, JavaServer Pages, tag libraries, etc.
Database access MySQL, Oracle, etc.

Purpose of web applications

A web application bundles all the web content into a single collection that can be used on any server compatible with servlet specification. The main purpose of web applications are three folds:

Web Container

A web container is a runtime platform that provides the services to web components. A Web container is essentially the component of a Web server that interacts with the servlets. The Web container is responsible for managing the lifecycle of servlets. In other words, a web container is essentially a servlet container.

Web Components

Web components provide the dynamic extension capabilities for a web server. When a web-based client such as a browser communicates with a Java EE application, it does so through web components. There are three types of web components:

Note: The JavaBeans components are not web components.

Request-response model

The communication between client and web tiers and the communication between web and data tiers adopt the fundamental request-response model.

Tomcat 6 Screen Shot

First Look of JavaServer Pages

Structures of Web Applications

Organization

Analysis of Duke Example

File structure of Duke

Since there are no servlets and JavaBeans in this example, the folder Duke\WEB-INF\classes is not needed. We do not use any libraries in this example, so there is no Duke\WEB-INF\lib folder.

Static resource

An image file: Duke\duke.waving.gif

Web components

Web components mean dynamic resouces of the web application. There are two web components in this example: Duke\index.jsp and Duke\response.jsp.

Code Listing: Duke\index.jsp
 
	1:	<%@page contentType="text/html"%>
	2:	<%@page pageEncoding="UTF-8"%>
	3:
	4:	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	5:	   "http://www.w3.org/TR/html4/loose.dtd">
	6:	
	7:	<html>
	8:	<head><title>Hello</title></head>
	9:	<body bgcolor="white">
	10:	<img src="duke.waving.gif"> 
	11:	<h2>Hello, my name is Duke. What's yours?</h2>
	12:	<form method="get">
	13:	<input type="text" name="username" size="25">
	14:	<p></p>
	15:	<input type="submit" value="Submit">
	16:	<input type="reset" value="Reset">
	17:	</form>
	18:
	19:	<%
	20:	   String name = request.getParameter("username");
	21:	   if (name != null) {
	22:	%>
	23:	       <%@include file="response.jsp" %>
	24:	<%
	25:	   }
	26:	%> 
	27:
	28:	</body>
	29:	</html>
	

Explanation:

Code Listing: Duke\response.jsp
	1:	<h2><font color="black">Hello, <%= request.getParameter("username") %>!</font></h2>
      

Explanation:

Deployment descriptor web.xml

Code Listing: Duke\WEB-INF\web.xml
           
	1:	<?xml version="1.0" encoding="UTF-8"?>
	2:
	3:	<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
	4:		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	5:		 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	6:		 version="2.4">
	7:	    <session-config>
	8:	        <session-timeout>
	9:	            30
	10:	        </session-timeout>
	11:	    </session-config>
	12:	    <welcome-file-list>
	13:		<welcome-file>
	14:	            index.jsp
	15:	        </welcome-file>
	16:	    </welcome-file-list>
	17:	</web-app>
        

Question: What would happen in Tomcat if there is no welcome file given in the web.xml?

Exercise

Problem:

Requirements:

==========The End==========