JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.

Slides:



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

Java Server Pages (JSP)
Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
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.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
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,
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.
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
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.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
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.
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.
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.
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.
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.
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.
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.
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.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
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.
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.
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 ( )
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
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.
 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,
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.
Apr 3, 2013 JSP Java Server Pages. 2 A “Hello World” servlet (from the Tomcat installation documentation) public class HelloServlet extends HttpServlet.
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 Directive and Objects. JSP Directives As discussed before There are 3 types of elements in JSP Directive Elements Scripting Elements Standard Action.
JSP Java Server Pages. Hello, !
Developing JavaServer Pages
Scripted Page Web App Development (Java Server Pages)
Pre-assessment Questions
Invoking Java Code from JSP
Java Server Pages.
JSP Directives 1-Jan-19.
JSP implicit objects & directive elements
Presentation transcript:

JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP

Overview JavaServerPages are similar to HTML files, but provide the ability to display dynamic content with Web pages. A JavaServer Page (JSP) is an HTML web page that contains embedded Java code. HTML Java Code HTML sample.jsp The HTML displays the static portion of the page (text and graphics). The Java code is used to generate dynamic content for the page (JDBC, RMI). A JSP separates user interfaces from content generation. This allows the separation of web page design from component development.

Overview When a JSP is requested by a user, the web server executes the Java code to create the dynamic portion of the page. Web Browser Web Server request response | | | | | HTML Java Code HTML sample.jsp HTML

The date is sample.jsp Java code to create a Date object and include it in the page Overview

Web Browser Web Server | | | | | How is the JSP file processed? The date is sample.jsp request Client sends HttpRequest using URL of JSP The date is Tue Jun 06 16:03:37 EDT 2000 response JSP returns an HTML page

Web Browser JSP File Web Server JSP ParserJava Source Java Compiler JSP Servlet request Web Page (HTML) response How is the JSP file processed?

Elements of a JSP Expressions – code fragment who results are placed into the page Scriplets – blocks of Java code embedded in the page Declarations – page-wide variable and method declarations Directives – global information about the page JSPs are composed of standard HTML tags and JSP tags. The JSP tags are categorized as follows:

JSP -- Expressions Expressions are variables or constants that are inserted into the data returned by the web server. Syntax The expression is evaluated, converted to a string, and the result is inserted into the page Examples

JSP -- Expressions JSP defines several predefined variables which may be used in expressions and scriplets. Here are a few: request – the HttpServletRequest response – the HttpServletResponse session – the HttpSession associated with the session out – the PrintWriter used to send output to the client | | | | | ~~ ~~ ~~ ~~ ~~~ ~~~~ JSP request response out

JSP -- Scriplets Scriptlets are blocks of Java code embedded within the JSP page Syntax Example <% int i; for(i = 0; i < 10; i ++ ) out.println( i ); %>

JSP -- Scriplets Example Scriplets are often used to conditionally construct parts of the HTML page. <% String answer = request.getParameter("ans"); if( answer.equals(“texas“) ) { %> Your answer is correct! Sorry, your answer is incorrect. scriptlet2.jsp

JSP -- Scriplets Where is San Antonio located? question.htm This form will send the data in the textfield to scriptlet2.jsp.

<% String answer = request.getParameter("ans"); if( answer.equals(“texas“) ) { %> Your answer is correct! Sorry, your answer is incorrect. scriptlet2.jsp response Your answer is correct! request ans = texas

<% String answer = request.getParameter("ans"); if( answer.equals(“texas“) ) { %> Your answer is correct! Sorry, your answer is incorrect. scriptlet2.jsp response Sorry, your answer is incorrect. request ans = nevada

JSP -- Declarations A declaration block defines Java variables and methods for subsequent use in expressions or scriptlets. The declared variable or method may be used throughout the page. Syntax Example <%! int cout = 0; private void increment ( ) { count++; } %>

JSP -- Declarations Example Here is a JSP that calculates the factorial of a number retrieved from a form. <%! public int fact( int x ) { if( x == 1 ) return 1; else return x * fact( x - 1 ); } %> Factorial Calculator <% String numberString = request.getParameter("number"); int number = Integer.parseInt(numberString); out.println(number + " ! = " + fact(number)); %> Try another one factcalc.jsp declaration

This form will send the data in the textfield to factcal.jsp. JSP -- Declarations Factorial Calculator Enter a number : factorial.htm

<%! public int fact( int x ) { if( x == 1 ) return 1; else return x * fact( x - 1 ); } %> Factorial Calculator <% String numberString = request.getParameter("number"); int number = Integer.parseInt(numberString); out.println(number + " ! = " + fact(number)); %> Try another one response factcalc.jsp Factorial Calculator 4 ! = 24 Try another one request number = 4

JSP -- Declarations Example Here is a JSP that counts the number of times a page is accessed. This page has been accessed times. counter.jsp

JSP -- Directives A directive is a global definition that dictates how the code is a JSP file will be processed. Directives are used to set page-level instructions, insert data from external files, and specify custom tag libraries Directives are placed at the beginning of the JSP file???. Syntax: There are three types of directives : page, include, taglib

JSP -- Directives page directive The page directive defines page dependent attributes: -- Identifies the scripting language used in the JSP file -- Returns the defined page if an error occurs in the JSP page import = “java.util.*, java.text.*” -- Defines packages that that will be used by the embedded scripts Other page directives are: extends, session, buffer, autoFlush, isThreadSafe, info, isErrorPage, contentType

JSP -- Directives include directive The include directive allows text to be inserted into the page: -- Inserts the contents of copyright.html into the JSP

The date is sample2.jsp Scripting language is java Import the package java.util Insert the file copyright.htm Copyright 2000 Allen copyright.htm