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.

Slides:



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

Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 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.
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives Chengyu Sun California State University, Los Angeles.
JSP Java Server Pages Reference:
DT228/3 Web Development JSP: Directives and Scripting elements.
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,
1 CS6320 – JSP L. Grewe 2 Java Server Pages Servlets require you to write out entire page delivered with print statements Servlets require you to write.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
1 JSP – Java Server Pages Representation and Management of Data on the Internet.
Introduction to JSP Based on: Marty Hall, Larry Brown, Core Servlets and JavaServer Pages.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Jordan Anastasiade. All rights reserved.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
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.
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.
SE-2840 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaServer Page.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
1 JSP – Java Server Page DBI – Representation and Management of Data on the Internet.
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)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
CS-4220 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
Java Server Pages Introduction. Servlet Drawbacks Web page designer will need to know servlets to design the page. Servlet will have to be compiled for.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
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.
Web Technologies Java Beans & JSP By Praveen Kumar G.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
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.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
JSP – Java Server Page DBI – Representation and Management of Data on the Internet.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
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.
1 Chapter 27 JavaServer Page. 2 Objectives F To know what is a JSP page is processed (§27.2). F To comprehend how a JSP page is processed (§27.3). F To.
INVOKING JAVA CODE WITH JSP SCRIPTING ELEMENTS. Creating Template Text A large percentage of your JSP document consists of static text (usually HTML),
 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.
DT228/3 Web Development JSP: Actions elements and JSTL.
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.
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.
JSP Java Server Pages. Hello, !
Developing JavaServer Pages
Java Server Pages.
Java Server Pages By: Tejashri Udavant..
COMP9321 Web Application Engineering Semester 2, 2017
Scripted Page Web App Development (Java Server Pages)
Pre-assessment Questions
Introduction to JSP Java Server Pages
Invoking Java Code from JSP
Java Server Pages (JSP)
Java Server Pages.
JSP Directives 1-Jan-19.
JSP implicit objects & directive elements
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)
Web Technologies Java Beans & JSP
Presentation transcript:

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 JSP page  JSPPage  HttpJspPage  Three main methods  jspInit()  jspDestroy()  _jspService(HttpServletRequest request, HttpServletResponse response)

Elements of a JavaServer Page  JSP Elements  “Template Text” – HTML  When request is processed  template text & dynamic content merged  result sent as response to browser  JSP Elements  Directive  Action  Scripting

Elements of a JavaServer Page  Directives  provide global information to the page  Action  perform action based on up-to-date information  Scripting  Declarative  for page-wide variable and method declaration  Scriptlets  the Java code embedded in the page  Expressions  Format the expression as a string for inclusion in the output of the page.

JSP Syntax HTML Comment  Comment can be viewed in the HTML source file -->  Example: <!-- This page was loaded on <%= (new java.util.Date ()).toLocaleString()%> -->  View source:

JSP Syntax Hidden Comment  Everything between the is ignored by the JSP container  Comment cannot be viewed in the HTML source file  Example: A Test of Comments

JSP Directives  A JSP directive is a statement that gives the JSP engine information for the page.  Used to provide information about the general set-up of the page. e.g. inclusion of header files, name of page to report errors, whether session tracking is required etc  Syntax   For Example:  scripting language used  session tracking required  name of page for error reporting

Types of Directive Elements   Define page-dependent attributes, such as scripting language, error page & buffering requires   Include a file during the translation phase.   Declares a tag library, containing custom actions, used in the page Each directive has a set of associated attributes (similar to some tags in HTML) Full list of attributes available at:

JSP Syntax Include Directive  Includes a static file  Example: main.jsp: Current date and time is: date.jsp: Output : Current date and time is: Mar 5, :56:50

Attribute for the page directive and possible values  language -- The language attribute defines the scripting language to be used in the page. The value "java" is the only value currently defined and is the default.  extends -- The extends attribute defines the (fully-qualified) class name of the superclass of the servlet class that is generated from this JSP page.  import -- The import attribute defines the set of classes and packages that must be imported in the servlet class definition.

Attribute for the page directive and possible values  session -- The session attribute defines whether the JSP page is participating in an HTTP session. The value is either true (the default) or false.  Buffer -- The buffer attribute defines the size of the buffer used in the output stream (a JspWriter object). The value is either none or Nkb.  autoFlush -- The autoFlush attribute defines whether the buffer output should be flushed automatically when the buffer is filled or whether an exception is thrown. The value is either true (automatically flush) or false (throw an exception). The default is true.

Attribute for the page directive and possible values  isThreadSafe -- The isThreadSafe attribute defines whether the JSP servlet implements the SingleThreadModel interface. The value is either true or false. The default is true.  Info -- The info attribute defines an informational string about the JSP page.  errorPage -- The errorPage attribute indicates another JSP page that will handle all runtime exceptions thrown by this JSP page. The value is a URL that is either relative to the current Web hierarchy or relative to the context root. For example, errorPage="error.jsp" (this is relative to the current hierarchy) or errorPage="/error/formErrors.jsp" (this is relative to the Web application's context root).

Attribute for the page directive and possible values  isErrorPage -- The isErrorPage attribute defines that the JSP page has been designed to be the target of another JSP page's errorPage attribute. The value is either true or false (default). All JSP pages that "are an error page" automatically have access to the exception implicit variable.

JSP action elements  Action elements are an important syntax element in JSP  They are represented by tags (as is HTML)  They assist JSP developers to develop in tags rather than scriplet programming  Instead of <%, they just use the < character (like HTML) For example: body

JSP action elements  Full syntax of JSP Action Elements is: action_body If the element doesn’t have a body, can lose the end tag and use shorthand syntax of:

JSP action elements  There are two types of JSP action elements: 1. JSP Pre – defined tags, also called Standarded Action Elements. 2. External tag library: Custom or JSTL(Java Standard tag library)

JSP standard action elements  jsp:useBean  jsp:setProperty  jsp:getProperty  jsp:param  jsp:include  jsp:forward  jsp:plugin  jsp:params  jsp:fallback

JSP standard action elements  Standard Action Example: tag  Example: Going to include hellouser.jsp... Executes the included JSP page and adds its output into the this page

JSP standard action elements  What’s difference from using the “include” derective?  The include directive includes the contents of another file at compilation time. Good for including common static code e.g. header file, footer file. Good on performance  included only once.  But, what if including dynamic common code (e.g. a navigation bar where links are read from the dB?).. need to re-run the file each time a request is made  JSP: include

JSP standard action elements  Standard Action Example: tag  Example: Error occurred…please wait Stops processing of one page and starts processing the page specified by the page attribute

JSP Declaration  The definition of class-level variables and methods  Syntax  Example <%! String var1 = “hi”; int count = 0; private void incrementCount() { count++; } %>

JSP Scriptlets  Scriptlets are defined as any block of valid Java code that resides between tags  This code will placed in the generated servlet _jspService() method.  Example <% String var1 = request.getParameter(“lname”); out.println(var1); %>

JSP Expressions  A JSP expression is a nice tool for embedding values within your HTML code.  Syntax  Example Counter value is

Scripting: Implicit JSP Objects  Request -- The HttpServletRequest object associated with the request  Response -- The HttpServletResponse object associated with the response that is sent back to the browser  pageContext -- This object encapsulates the environment of a single request for this JSP page  Session -- The HttpSession object associated with the session for the given user of the request. This variable is only meaningful if the JSP page is participating in an HTTP session

Scripting: Implicit JSP Objects  Application -- The ServletContext object for the Web application  Out -- The JspWriter object associated with the output stream of the response  Config -- The ServletConfig object associated with the servlet for this JSP page  Exception -- The Throwable object that was thrown by some other JSP page. This variable is only available in a "JSP error page."

Scripting: Implicit JSP Objects  Example Use Out <% //print a simple message using the implicit out object out.println( " Hello! " ); %>

Use of Implicit Objects…  The following information was part of this request Request method Request URI Request Protocal Server Name Server Port Remote Address Remote Host

Use of Implicit Objects…  Example Use Request <% //print a simple message using the implicit out object out.println( " Hello! " + request.getParameter("user") + " " ); %>