directive attribute1= value1 attribute2= value2... attributen= valuen %>

Similar documents
Unit 5 JSP (Java Server Pages)

Java Server Page (JSP)

UNIT -5. Java Server Page

Experiment No: Group B_2

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

Advantage of JSP over Servlet

JavaServer Pages. What is JavaServer Pages?

A Gentle Introduction to Java Server Pages

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

COMP9321 Web Application Engineering

JSP MOCK TEST JSP MOCK TEST IV

Unit 4 Java Server Pages

JSP Scripting Elements

JSP MOCK TEST JSP MOCK TEST III

JSP. Basic Elements. For a Tutorial, see:

Ch04 JavaServer Pages (JSP)

COMP9321 Web Application Engineering

Trabalhando com JavaServer Pages (JSP)

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

COMP9321 Web Application Engineering

Trabalhando com JavaServer Pages (JSP)

Introduction to JSP and Servlets Training 5-days

One application has servlet context(s).

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:

About the Authors. Who Should Read This Book. How This Book Is Organized

Module 5 Developing with JavaServer Pages Technology

SNS COLLEGE OF ENGINEERING, Coimbatore

JavaServer Pages (JSP)

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Java Server Pages. JSP Part II

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

A JavaBean is a class file that stores Java code for a JSP

SSC - Web development Model-View-Controller for Java Servlet

S imilar to JavaBeans, custom tags provide a way for

CS506 Web Design & Development Final Term Solved MCQs with Reference

Exercise. (1) Which of the following can not be used as the scope when using a JavaBean with JSP? a. application b. session c. request d.

Scope and State Handling in JSP

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

More JSP. Advanced Topics in Java. Khalid Azim Mughal Version date: ATIJ More JSP 1/42

112. Introduction to JSP

Advanced Java Programming

CE212 Web Application Programming Part 3

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Oracle 1z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Practice Test. Version:

Anno Accademico Laboratorio di Tecnologie Web. Sviluppo di applicazioni web JSP

Java4340r: Review. R.G. (Dick) Baldwin. 1 Table of Contents. 2 Preface

112-WL. Introduction to JSP with WebLogic

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

Chapter 10 Servlets and Java Server Pages

SESM Components and Techniques

Basic Principles of JSPs

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

01KPS BF Progettazione di applicazioni web

Java E-Commerce Martin Cooke,

JSP: Servlets Turned Inside Out

20/08/56. Java Technology, Faculty of Computer Engineering, KMITL 1

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY- VIRUDHUNAGAR

JSF & Struts 1, 4, 7, 2, 5, 6, 3 2, 4, 3, 1, 6, 5, 7 1, 4, 2, 5, 6, 3, 7 1, 2, 4, 5, 6, 3, 7

Fast Track to Java EE

First Simple Interactive JSP example

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

SECTION I: JAVA SERVLETS AND JAVA SERVER PAGES

COMP201 Java Programming

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

GUJARAT TECHNOLOGICAL UNIVERSITY

Université du Québec à Montréal

1 CUSTOM TAG FUNDAMENTALS PREFACE... xiii. ACKNOWLEDGMENTS... xix. Using Custom Tags The JSP File 5. Defining Custom Tags The TLD 6

UNIT I Java Bean, HTML & Javascript

CHAPTER 1. Core Syntax Reference

CSC309: Introduction to Web Programming. Lecture 11

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Web Programming. Lecture 11. University of Toronto

Component-Based Software Engineering. ECE493-Topic 5 Winter Lecture 26 Java Enterprise (Part D)

JSP - ACTIONS. There is only one syntax for the Action element, as it conforms to the XML standard:

Introduction to Programming Using Java (98-388)

Modernizing Java Server Pages By Transformation. S h a n n o n X u T h o m a s D e a n Q u e e n s U n i v e r s i t y

Session 12. JSP Tag Library (JSTL) Reading & Reference

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

JSF. What is JSF (Java Server Faces)?

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

Enterprise Computing with Java MCA-305 UNIT II. Learning Objectives. JSP Basics. 9/17/2013MCA-305, Enterprise Computing in Java

Adv. Web Technology 3) Java Server Pages

Java Training JAVA. Introduction of Java

Table of Contents. Introduction... xxi

Java Server Pages(JSP) Unit VI

Principles and Techniques of DBMS 6 JSP & Servlet

Session 11. Expression Language (EL) Reading

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

ddfffddd CS506 FINAL TERMS SOLVED BY MCQS GHAZAL FROM IEMS CAMPUS SMD CS506 Mcqs file solved by ghazal

Courses For Event Java Advanced Summer Training 2018

web.xml Deployment Descriptor Elements

ADVANCED JAVA TRAINING IN BANGALORE

Call: Core&Advanced Java Springframeworks Course Content:35-40hours Course Outline

C H A P T E RJSP.2. JSP.2.1 Syntax of expressions in JSP pages: ${} vs #{}

Page 1

JavaEE Interview Prep

Transcription:

JSP Standard Syntax Besides HTML tag elements, JSP provides four basic categories of constructors (markup tags): directives, scripting elements, standard actions, and comments. You can author a JSP page either in JSP standard syntax format or in a pure XML document format. The JSP XML format document complies with the XML specification and can be used for data interchange.

JSP Directives A JSP directive instructs the JSP engine to configure the structure of the Servlet that is generated from the JSP pages. The JSP directives do not produce any Java target code for the translated Servlet class. The JSP directives only affect the Servlet settings such as page settings, and inclusion of packages, classes, and custom tag libraries. JSP directives are processed at JSP translation time instead of execution time. The general syntax of a JSP directive is: <%@ directive attribute1= value1 attribute2= value2... attributen= valuen %>

JSP page Directive The JSP page directive directs the JSP engine to specify the page setting during the Servlet translation time. It has many attributes. Some attributes have their default values. All the attributes may only have one value except the import attribute, which may have multiple values. Here is the summary of all attributes of page directive. The value of the attribute must be enclosed in a pair of quotation marks. The values in bold indicate the default values. The often used attributes are listed at the top of following list.

JSP page Directive (cont.)

JSP page Directive (cont.)

JSP include Directive The JSP include directive instructs the JSP engine to include the actual contents of another file that may be a static HTML page, text file, or JSP file. The included file may declare methods or variables. The included file is inserted into the current page at translation time. People refer to this include directive as a static include. The syntax of include directive is: <%@ include file=<relative path>/<file name> %> A banner page, heading page, copyright page, or a footnote page are perfect examples of files to be included in a JSP page.

JSP taglib Directive The taglib directive is used to include a custom tag library so that the JSP can make use of the tags defined in the tag library. There are two types of tags: standard tags and user defined custom tags. JSP developers can encapsulate complex and often used server side tasks in custom tags for reuse purposes. This is similar to standard tags such as the JSP usebean action tag that will be introduced soon.

JSP taglib Directive Each self-defined tag must have three components: A tag handler class that specifies the behavior of the new defined tag A Tag Library Descriptor (TLD) XML file with an extension.tld that describes all tags in the tag library. It maps the tag names to their tag handler classes in the library A JSP page that uses the user defined tag.

JSP taglib Directive (cont.) The syntax of taglib directive is: <%@ taglib uri= <taglib.tld> prefix= <p_name> %> where the Uniform Resource Identifier (URI) attribute specifies the absolute or relative URI to the TLD file. For example, you can use a custom tag in this way: <p_name:mytag>... </p_name:mytag> where mytag is defined in taglib.tld with the prefix p_name.

JSP Scripting Elements There are three scripting elements in JSP syntax. All of them are Java code. Declarative elements start with <%! Expression elements start with <%= Scriplet elements start with <%

Declaration Element The JSP declaration element defines page-scope variables to store information or defines supporting methods that the rest of a JSP page may need. Declaration elements do not produce outputs. The declaration content must be a valid Java statement or multiple statements separated by semicolons. The contents of the declaration scripting element will be translated into Servlet Java code and inserted into the body of the translated corresponding Servlet code somewhere outside of any methods.

Its syntax is Declaration Element (cont.) <%! Java Code %> For example, you can define page scope primitive or class variables as <%! int i=0; Double d; %>

Declaration Element (cont.) You can also declare methods by declaration scripting elements. For example, you can declare the JSP life cycle methods jspinit() and jspdestroy() as follows : <%! Connection conn %>... <%! public void jspinit() { try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = java.sql.drivermanager.getconnection( "jdbc:oracle:oci9:mydb","scott","tiger"); } catch (Exception e) {...} } %>

Declaration Element (cont.) This JSP method will be part of the init() method of the Servlet after JSP translation. It will be called when the object of the corresponding Servlet class is instantiated. It is called only once so that it can save a lot of resources such as database connection cost in above example. <%! public void jspdestroy() { try { if (conn!= null) conn.close(); } catch (java.sql.sqlexception e) {...} } %> The jspdestroy() method will be part of destroy() method of the Servlet.when the Servlet instance ends, it clears up all resources the JSP has acquired.

Expression Scripting Elements In JSP, the results of an expression evaluation are always converted to a string and directly included in the output page. Typically, expressions are used to display simple values of variables or return values of shared data by invoking a bean's getter methods. The JSP expression syntax is given here. The predefined JSP objects such as request, response, and session can also be used within the expression element to make the expression as simple as possible. <%= expr %> // No semicolon <%= i * j + k %> <%= mybean.getsalary() %> <%= request.getremotehost() %>

Scriptlet Element JSP scriptlets are embedded within <%... %> tags. They are executed at the runtime. The syntax is <% Java code %> The scriptlets are inserted into the _jspservice() method of the translated Servlet code which is invoked by the Servlet service() method. This java code is executed when the request is serviced by the JSP page. You can put any valid Java code within a scriptlet element, and it is not limited to one line of source code. For example, the following displays the counter during execution of a loop, combining the use of the expressions element and the scriptlets element: <% for (int i=1; i<=4; i++) { %> The counter is now <% = i %> <% } %>

JSP Standard Actions JSP standard action elements simplify the access actions to other Web components such as Servlet, JSP, or JavaBean components. The format is <jsp:action other-info />

JSP forward Action <jsp:forward page="another page" /> This action forwards the request to another page, i.e. an internal redirect. For example, it forwards the control from current page to second.jsp.... <jsp:forward page='second.jsp'/>...

JSP include Action Addition to the JSP page include directive that includes a page at the JSP translation time, JSP also supports an action that can dynamically include a page at run-time. <jsp:include page = <jsp or html page> flush= true false /> If the flush attribute is set to true, the included page will update when the JSP is updated. Remember that the include directive only copies the contents once and never changes afterwards since it is static. The purpose of include action is to include the other page to be part of current page. It is used for such as conditionally including other pages at run time.