Project J2EE Architecture,
J2EE application Structure
Enterprise Archive (ear) file
Application.xml inside the META
Java Archive (jar) file
jar.xml inside the META
Web Archive (war) file
web.xml inside the WEB
Java Server Pages (JSPs)
JSPs are built on servlet technology.
JSPs are an HTML page with special tags
JSP tags can contain Java code.
JSP file extension is .jsp rather than .htm or
The JSP engine parses the .jsp and creates
a Java servlet source file. It then compiles
the source file into a class file.
What happens when you
User traverses to a JSP page (.jsp) and browser makes the
The JSP request gets sent to the Web server.
The Web server recognizes .jsp and passes the JSP file to
the JSP Servlet Engine.
If the JSP file has been called the first time, the JSP file is
The next step is to generate a Servlet from the JSP file. All
the HTML required is converted to println statements.
The Servlet source code is compiled into a class.
The Servlet is instantiated, calling the
HTML from the Servlet output is sent via the Internet.
HTML results are displayed on the user's web browser
Creating your first JSP page
<title>My first JSP page </title>
<%@ page language="java" %>
<% out.println("Hello World"); %>
Type the code above into a text file. Name the file
helloworld.jsp. Place this in the correct directory on
your JSP web server and call it via your browser
Scriptlet tag (previous example)
Used for declaring variables or methods (no output).
Before the declaration you must have <%!
At the end of the declaration, the developer must have %>
Code placed in this tag must end in a semicolon ( ; ).
Declarations are used with JSP expressions or scriptlets.
private int counter = 0 ;
private String get Account ( int accountNo) ;
Expression tag ( <%= %>)
This tag allows the developer to embed any Java
expression and is short for out.println().
A semicolon ( ; ) does not appear at the end of the code
inside the tag.
For example, to show the current date and time.
Date : <%= new java.util.Date() %>
( <%@ directive
A JSP directive gives special information about the page
to the JSP Engine.
There are three main types of directives:
processing information for this page.
files to be included.
tag library to be used in this page.
Import : Import all the classes in a
java package into the current JSP
page. This allows the JSP page to use
other java classes.
<%@ page import = "java.util.*" %>
Allows a JSP developer to include contents of a file inside another. Typically
include files are used for navigation, tables, headers and footers that are
common to multiple pages.
Two examples of using include files:
This includes the html from privacy.html found in the include directory into the
current jsp page.
<%@ include file = "include/privacy.html" %>
or to include a naviagation menu (jsp file) found in the current directory.
<%@ include file = "navigation.jsp" %>
Tag Lib directive
A tag lib is a collection of custom tags that can
be used by the page.
<%@ taglib uri = "tag library URI" prefix = "tag
Custom tags were introduced in JSP 1.1 and
allow JSP developers to hide complex
server side code from web designers.
... %> )
Between <% and %> tags, any valid Java code is called a Scriptlet.
This code can access any variable or bean declared.
For example, to print a variable.
String username = “Orest" ;
out.println ( username ) ;
There are three main roles of action tags :
enable the use of server side Javabeans
transfer control between pages
browser independent support for applets.
To use a Javabean in a JSP page use the following syntax:
<jsp : usebean id =
" ...." scope = "application" class = "com..." />
The following is a list of Javabean scopes:
valid until page completes.
bean instance lasts for the client request
bean lasts for the client session.
bean instance created and lasts until application ends.
declares two variables; one string used to stored the name of a website and
an integer called counter that displays the number of times the page has
been accessed. There is also a private method declared to increment the
counter. The website name and counter value are displayed.
<TITLE> JSP Example</TITLE>
<font face=verdana color=darkblue>
public String writeThis(int x)
for (int i = 1; i < x; i++)
myText = myText + "<font size=" + i + " color=darkred face=verdana>VisualBuilder JSP
This is a simple example
<%= writeThis(8) %>
The implicit objects are :
Represents the JSP page and is used to call any methods defined by the servlet class.
Stores the Servlet configuration data.
Access to information associated with a request. This object is normally used in looking up parameter
values and cookies.
JBOSS Deployment of JSPs
0) Create a HelloWorld folder for storing your JSP and DD.
1) Write JSP File
This JSP simply displays a greeting along with the current date and time.
2) Create Deployment Descriptor
In the "HelloWorld" folder, create a sub folder called "WEB
INF", and in that folder create a file
named "web.xml" as:
The deployment descriptor provides information to JBoss about your web application.
3) Create WAR Builder & Deployer
In the "HelloWorld" folder, create a file called "Deploy.bat" as:
cvf helloworld.war *.jsp WEB
copy helloworld.war %JBossHome%
This script uses Java's JAR utility to zip up the appropriate contents into a WAR file.
JSP Deployment (cont)
4) Do It
Run the "Deploy.bat" file.
5) Test Your Web Page
In a browser, open "
and click on the "hi.jsp" link.
Now explore the JBoss console at
Click on "JBoss Web Console"
and expand "J2EE Domains", "Manager", and
Select "helloworld.war" to see information
about your web application.
J2EE application Structure
Import requirements (non
1. Scalability and Reliability
2. Open Source (costs)
Drive Architecture and Technology
J2EE (JBoss) Open Source
(Yahoo Java script API)
MySQL Open Source
Develop .war/jar files
.war file contains html and jsps that
can create “java objects” based on
user/password from user
.jar file contains entity EJBs that can
store information into MySQL
Divide into Teams
Exchange Contact Info
Start Planning a time table
Who’s the leader?
What are the roles?
Who’s the liaison with the other team?