CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application....

24
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha :- Puja Mehta (102163) Mona Nagpure (102147)

Transcript of CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application....

Page 1: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

CS562 Advanced Java and Internet Application

Introduction to the Computer Warehouse Web Application.

Java Server Pages (JSP) Technology.

By Team Alpha :- Puja Mehta (102163) Mona Nagpure (102147)

Page 2: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Table of Contents

1. Introduction to Computer Warehouse Application

2. Architecture3. Introduction to JSP Technology4. What is JSP?5. Why JSP?6. Role of JSP7. Features of JSP Technology8. Advantages and Disadvantages of JSP9. Future of JSP

Page 3: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Introduction

The Computer Warehouse is a Web Site for a fictional company that allows a user to browse through a catalog of the company’s products such as laptops, desktops and various computer accessories.

The user can select products, add products to a cart and purchase them using a credit card.

The web site accepts the order and displays an invoice receipt for the purchase.

The web site allows the user to join a email list.

Page 4: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Architecture

HTML Files JSP Files

Other Java Classes

JavaBeansServlets

Presentation Layer

Business Rules Layer

Database

Page 5: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Architecture

The presentation layer consists of HTML pages and JSPs.

The business rules layer consists of servlets and java classes.

The data is stored in a relational database.

Page 6: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

THE FOLLOWING SLIDES PROVIDE AN OVERVIEW OF THE JSP TECHNOLOGY, DESCRIBES THE KEY COMPONENTS OF A JSP PAGE

IN THE CONTEXT OF SOME SIMPLE EXAMPLES.

Introduction to Java Server Pages (JSP)

Page 7: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

What is JSP ?

A Java Server Page, or JSP, consists of Java code that is embedded within HTML Code.

When a JSP is requested, the JSP engine translates it into a Servlet and compiles it. The Servlet is run by the servlet engine.

For Java web applications Servlets are used to do the processing and JSP’s are used to present the user interface.

Page 8: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Why JSP

Separating content generation from presentation.

Simplifying page development with tags.

Benefits of Java Technology.

Works with a wide array of existing web servers and tools available.

Page 9: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Role of JSP

JSP is focused on simplifying the creation and maintenance of HTML and is best for task oriented towards presentation.

In Computer Warehouse Web Application JSP’s are used extensively to generate dynamic web pages.

This application makes use of JSPs to accept user input, create catalog pages, display invoices, provide forms to allow users to join email lists etc…

Thus JSPs play an important role in creating a user friendly interface to this application.

Page 10: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

The Home page

Page 11: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

The Catalog page

Page 12: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

The Join Email List Page

Page 13: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Features of Java Server Pages (JSP) Technology

Scriptlets

Expressions

Directives

Comments

Page 14: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

JSP tags

Tag Name Purpose

<% %> JSP Scriptlets To insert a block of Java statements.

<%= %>

JSP Expression To display the string value of an expression.

<%@ %>

JSP Directive To set conditions that apply to the entire JSP.

<%-- --%>

JSP Comment To tell the JSP engine to ignore code.

Page 15: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

JSP Scriptlets

Scriptlets Syntax :- <% Java Statement %> Example:-

<%String fn = request.getParameter(“firstName”);

%>

Page 16: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

JSP Expressions

JSP Expression Syntax :- <%= any Java expression that can be

converted to a string %>

Example:-

The first name is <%= fn%>

Page 17: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

JSP Directive

JSP Directive Syntax :- <%@directive attribute="value" %> Example:-

page: page is used to provide the information about it.Example: <%@page language="java" %> 

import is used to import classes in a JSP.Example: <%@ page import=“business.*” %>

Page 18: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

JSP Comments

JSP Comment Syntax :- <%-- String --%> Example :-

<%-- This is a JSP Comment --%>

Page 19: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Include Action

To include a file in a JSP at runtime, the include action can be used.

When include action is used, the generated servlet uses a runtime call to get the included file, and any changes to the included file will appear in the JSP the next time it is requested. Syntax:- <jsp:include page=“fileLocationAndName”/> Example:-<jsp:include

page=“/includes/header.html”/>

Page 20: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

How to request a JSP

With a form tag the Method attribute is used to specify the HTTP method to request a JSP and Action attribute specifies the URL of the JSP.

The two Methods are Get and Post.The Get Method displays the parameters that

are passed to the JSP in the browser’s URL. The Post Method does not display the parameters.

Alternatively, an Anchor tag can be used to call a JSP. It always uses the Get Method.

Page 21: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Code (join_email_list.jsp)

<jsp:include page="/includes/header.html" /><jsp:include page="/includes/column_left_home.jsp" /> <html>……<form action="display_email_entry.jsp" method="get">

<table cellspacing="5" border="0"> <tr> <td align="right">First Name:</td> <td><input type="text"

name="firstName"></td> </tr>

…….. <tr> <td></td> <td><br><input type="submit"

value="Submit"></td> </tr> </table> </form>

Page 22: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Code (disp_email_entry.jsp)

<%--use scriplets in jsp to retrieve parameters --%><%

String firstName = request.getParameter("firstName");String lastName = request.getParameter("lastName");String emailAddress = request.getParameter("emailAddress");

%><td>

<h1>Thank you for joining our email list</h1><p>Here is the information that you entered:</p><table cellspacing="5" cellpadding="5" border="1"><tr>

<td align="right">First Name</td><%--use jsp expressions to display parameters --%><td><%= firstName %></td>

</tr>…..

<form action="join_email_list.jsp" method="post"><input type="submit" value="Return">

</form>

Page 23: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Advantages & Disadvantages

Advantages Extend the JSP language by using pluggable, reusable

tag libraries available. Easy to read, write and maintain pages.

Disadvantages JSP can be effectively used only by someone with

some degree of Java knowledge. Debugging JSP’s is difficult since JSP page will be

converted to Java Page .

Page 24: CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.

Future of JSP

Designed to be an open, extensible standard for building dynamic web pages.

JSP specification is open and portable, allowing programmers to author and deploy JSP pages anywhere (e.g. Tomcat , IBM )

Tool vendors will extend its functionality by providing customized tag libraries for specialized functions.