CS420 Software Engineering in Practice

thickbugSoftware and s/w Development

Oct 28, 2013 (3 years and 11 months ago)

62 views

CS420


Software Engineering
in Practice

Lab Review,

Project J2EE Architecture,

& JSPs


J2EE application Structure

EJBs

Web component

EJB DD

EJB class

Remote class

Home class

Web DD

JSP files

Servlet Class

Pictures (GIF/JPG)

HTML files

J2EE Application

J2EE DD

.war file

.ear file

.jar file

DD =
Deployment
Descriptor

Standard deployment
descriptors


Enterprise Archive (ear) file


Application.xml inside the META
-
INF
directory


Java Archive (jar) file


ejb
-
jar.xml inside the META
-
INF directory


Web Archive (war) file


web.xml inside the WEB
-
INF directory

Java Server Pages (JSPs)


JSPs are built on servlet technology.


JSPs are an HTML page with special tags
embedded.


JSP tags can contain Java code.


JSP file extension is .jsp rather than .htm or
.html.


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
access JSP?


User traverses to a JSP page (.jsp) and browser makes the
request.


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
parsed.


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
init

and
service

methods.


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

<html>

<head>

<title>My first JSP page </title>

</head>

<body>

<%@ page language="java" %>

<% out.println("Hello World"); %>


</body>

</html>



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



JSP Tags


Scriptlet tag (previous example)


Declaration tag


Expression tag


Directive tag


Action tag

Declarative

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.




Example:




<%!






private int counter = 0 ;


private String get Account ( int accountNo) ;

%>

Expression Tag

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 tag

( <%@ directive

... %>)



A JSP directive gives special information about the page
to the JSP Engine.



There are three main types of directives:



1)


page

-

processing information for this page.

2)


Include

-

files to be included.

3)


Tag library

-

tag library to be used in this page.

Import Directive


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.*" %>

Include directive




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
Prefix" %>



Custom tags were introduced in JSP 1.1 and
allow JSP developers to hide complex
server side code from web designers.



Scriptlet tag

( <%

... %> )





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 ) ;




%>

Action tag


There are three main roles of action tags :




1)


enable the use of server side Javabeans

2)


transfer control between pages

3)


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:




page

-

valid until page completes.

request

-

bean instance lasts for the client request

session

-

bean lasts for the client session.

application

-

bean instance created and lasts until application ends.


Another Example


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.



<HTML>

<HEAD>

<TITLE> JSP Example</TITLE>

</HEAD>

<BODY>

<font face=verdana color=darkblue>

JSP loop

<BR> <BR>

<%!

public String writeThis(int x)

{


String myText="";


for (int i = 1; i < x; i++)



myText = myText + "<font size=" + i + " color=darkred face=verdana>VisualBuilder JSP
Tutorial</font><br>" ;


return myText;

}

%>



This is a simple example

<br>

<%= writeThis(8) %>

</font>

</BODY>

</HTML>


Implicit Objects


The implicit objects are :








Request



Response



Out



Session



PageContent



Application



Config



Page






Page object




Represents the JSP page and is used to call any methods defined by the servlet class.




Config object




Stores the Servlet configuration data.




Request object




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:
web.xml


<web
-
app>

<display
-
name>Hello World</display
-
name>

</web
-
app>



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:
Deploy.bat



set JAVA_HOME=C:
\
Program Files
\
Java
\
jdk1.5.0_06

set JBossHome=C:
\
Apps
\
JBoss
\
jboss
-
4.0.3SP1

"%JAVA_HOME%
\
bin
\
jar.exe"
-
cvf helloworld.war *.jsp WEB
-
INF

copy helloworld.war %JBossHome%
\
server
\
default
\
deploy

pause



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 "
http://localhost:8080/helloworld
"
and click on the "hi.jsp" link.


Now explore the JBoss console at
"
http://localhost:8080
".


Click on "JBoss Web Console"
and expand "J2EE Domains", "Manager", and
"JBoss".


Select "helloworld.war" to see information
about your web application.


J2EE application Structure

EJBs

Web component

EJB DD

EJB class

Remote class

Home class

Web DD

JSP files

Servlet Class

Pictures (GIF/JPG)

HTML files

J2EE Application

J2EE DD

.war file

.ear file

.jar file

DD =
Deployment
Descriptor

Our Project:
Location Based
Service Applications

Server Team:


Client Side

Travis

Rolf

Christopher

Lance

Stephen

Yaroslav

Soren

Taylor

Brandon

Project Statement


?

Requirements.


Import requirements (non
-
functional):


1. Scalability and Reliability

2. Open Source (costs)


3. Performance

Non
-
Functional Requirements
Drive Architecture and Technology


J2EE (JBoss) Open Source


(Yahoo Java script API)


MySQL Open Source

Phase 1.


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?