JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Advertisements

JSP and Servelets.
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JSP Java Server Pages Softsmith Infotech.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Jsp (Java Server Page) Is a server side program.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
Web Technologies Java Beans & JSP By Praveen Kumar G.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
JSP Java Server Pages. Hello, !
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Developing JavaServer Pages
Java Server Pages.
Java Server Pages By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Invoking Java Code from JSP
MSIS 655 Advanced Business Applications Programming
Introduction to Java Server Pages
Java Server Pages B.Ramamurthy.
Tutorial 10: Programming with javascript
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Scripted Page Web Application Development (Java Server Pages)
Presentation transcript:

JSP BASICS AND ARCHITECTURE

Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.

What are JSP? JSP is a specification and not a product but a specification. JSP More on line of the J2EE specification. Can utilize the Beans to separate the code out. Is compiled to Servlet the first time call is received for the page.

THE PROCESS JSP Servlet Client JSP JSP First Request Generates Response Text Uses

A SIMPLE JSP CODE import=“java.util.Date”% The current time is

The Container According to the JSP specifications that the servlets implement the Servlets must extend from:  Specified by JSP author via. Extends command. Or  A container specific Implementation class that implements javax.servlet.jsp.JSPPage interface.

The JSP Life Cycle public void jspInit() used for initialization purposes defined in javax.servlet.jsp.JSPpage Interface. public void jspDestroy() used for performing cleanup operations defined in javax.servlet.jsp.JSPPage Interface. public void _jspService(HttpServletRequest request, HttpServletResponese response) throws ServletException,IOException. The implementation of this method is generated by the container and should never be provided by Page authors.

General Rules for JSP Pages JSP tags are case sensitive. Attribute values in tags always appear quoted,Single or double. Eg: body Or The Second one is valid in case when there is no body.

General Rules for JSP Pages The character \ can be used as an escape character eg: to use %. URL that does not start with / are interpreted relative to the current JSP. URL starting with a /, called a context relative path, is interpreted with reference to the web application to which the JSP page belongs. Any white spaces with in the body text of a document are not significant although they are preserved during translation into a servlet.

Types of JSP Tags Directives. Scripting Elements. Actions.

JSP Directives They serve as messages to the JSP container from the JSP. Used to set global values as  Class Declarations  Methods to be implemented.  Output Content Type. They don’t produce any output to the user. Affects the whole file but only that file.

Types of JSP Directives page Directive. include Directive. taglib Directive.

page Directive Used to define and manipulate a number of page dependent attributes that affect the whole JSP. A page can contain any number of page directives, in any order, anywhere in the JSP.They are assimilated during translation. There can be only one occurrence of attribute/value pair defined by the page directives.

Program utilizing Page Directives page language="Java" session="true" import="java.rmi.*,java.util.*" session="true" buffer="12kb" autoFlush="true" info="my page directive jsp" errorPage="error.jsp" isErrorPage="false" isThreadSafe="false" %>

Program utilizing Page Directives Page Directive test Page Page directive test page This is a JSP to test the page directive.

Error in the Code This code will throw an error at present because the language page directive has been kept there for future use if JSP containers support multiple languages. At present this is not supported therefore it will through could not locate style sheet for JAVA error.

include Directive It instructs the container to include the content of the resource in the current JSP by inserting it inline. The include action occurs at runtime. Eg: The only available attribute file specifies the file name to be included. The included file can be a static resource such as an HTML file or another JSP. The code is inserted inline.

A simple Include Directive code Include Directive test page 1 Include directive test page 1

The copyright HTML file © 2000 Wrox Press

Output Include directive test page 1 © 2000 Wrox Press

taglib Directive This directive allows the page to use tag extensions (custom tags). It names the tag library that contains the compiled Java code. Eg:

Scripting Elements These allow Java Code – variable or method declarations, scriptlets (arbitrary Java code) and expressions to be inserted into your JSP page.

Types of Scripting Elements They are of three types: Declarations Scriptlets Expressions

Declarations A declaration is a block of Java code that is used to define class wide variables and methods in the generated servlet. Declarations are initialized when the JSP page is initialized. Syntax :

Scriptlets A scriptlet is a block of code that is executed during the request processing time. All the scriptlets in the JSP are combined in the order they appear in the code. As expected all the code for the scriptlets is put into the service() method of the servlet. Syntax:

Expressions The expression is a shorthand notation for a scriptlet that sends the value of Java expression back to the client. The expression is evaluated at HTTP request processing time and the result is converted to sting and displayed. In case the result of the expression is an object the conversation is done by using the objects toString() method. Syntax:

Standard Actions Standard Actions are tags that affect the runtime behavior of the JSP and the response sent back to the user. They have to provided by the container irrespective of the usage. During compilation into the servlet, the container comes across the this tag and replaces it with Java code that corresponds to the required predefined task.

Types of the Standard Action

This tag is used to instantiate a Java bean, or locate bean instance and assign it to a variable name (or id). We can also specify the lifetime of an object by giving it a specific name.

It is used with the action to set the value of bean properties. The properties in a bean can be set either:  At request time from parameters in the request object.  At request time from an evaluated expression.  From a specified string. Syntax:

It is used to access the properties of a bean. It accesses a property, converts it into a String, and prints it into the output stream of the client. Syntax:

Example utilizing For this example we will first of all create an HTML file beans.html in which user can insert his name and choose his favorite language from the drop down menu. Another file beans.jsp will be used to set the bean properties as per the values entered by the user and then by utilizing the methods defined in the LanguageBean.class it retrieves the information and displays it to the user.

beans.html useBean action test page useBean action test page Please enter your user name : What is your favorite programming language?

beans.html continued.. Java c++ Perl

beans.jsp useBean action test result

beans.jsp continued… useBean action test result Hello,. Your favorite language is.

beans.jsp continued… My comments on your favorite language:

LanguageBean.class public class LanguageBean{ private String name; private String language; public LanguageBean() {} public void setName(String name){ this.name=name; }

LanguageBean.class continued.. public String getName(){ return name; } public void setLanguage(String language){ this.language=language; }

LanguageBean.class continued.. public String getLanguage(){ return language; } public String getLanguageComments(){ if(language.equals("Java")){ return "The king of OOP languages."; }

LanguageBean.class continued.. else if(language.equals("c++")){ return "Rather too complex for some folks' liking."; } else if (language.equals("perl")){ return "OK if you like incomprehensible code."; }else{ return "Sorry, i have never heard of" +language+"."; }

Output of the Code useBean action test result Hello, Navdeep Mahajan. Your favorite language is Java. My comments on your favorite language: The king of OOP languages.

It is used to provide other tags with additional information in form of name value pairs. Syntax:

This action allows the static or dynamic resource, specified by the URL to be included in the current JSP at request processing time. The included page has access to only JspWriter object. It cannot set headers and cookies. It include page cannot have jsp tags. If the page output is buffered then the buffer is flushed prior to the inclusion. It has a small penalty on the efficiency.

Syntax: ……

It allows the request to be forwaded to the another JSP, to a servlet, or to a static resource. Execution in the current JSP stops when it encounters the tag,the buffer is cleared, and the request is modified..

Syntax: …..

It is used in pages to generate client browser specific HTML tags like or that result in the download of the Java Plug-in Software, if required,followed by the execution of the applet or JavaBeans component that is specified in the tag.

supported tags It supports two additional support tags: ,to pass additional parameters to the applet or the java beans component. , to specify the content to be displayed in the client browser if the plugin cannot be started because the generated tags are not supported.

Syntax

Syntax continued.. ……… Alternate text to display