CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application....
-
Upload
coral-verity-eaton -
Category
Documents
-
view
221 -
download
0
Transcript of CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application....
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)
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
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.
Architecture
HTML Files JSP Files
Other Java Classes
JavaBeansServlets
Presentation Layer
Business Rules Layer
Database
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.
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)
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.
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.
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.
The Home page
The Catalog page
The Join Email List Page
Features of Java Server Pages (JSP) Technology
Scriptlets
Expressions
Directives
Comments
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.
JSP Scriptlets
Scriptlets Syntax :- <% Java Statement %> Example:-
<%String fn = request.getParameter(“firstName”);
%>
JSP Expressions
JSP Expression Syntax :- <%= any Java expression that can be
converted to a string %>
Example:-
The first name is <%= fn%>
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.*” %>
JSP Comments
JSP Comment Syntax :- <%-- String --%> Example :-
<%-- This is a JSP Comment --%>
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”/>
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.
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>
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>
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 .
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.