Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.

Slides:



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

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.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
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 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.
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 Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Introduction Servlets and JSP Celsina Bignoli
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.
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.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
1 APPENDIX D OVERVIEW OF JSP, JSTL, and EL TAGS. 2 OVERVIEW OF JSP, JSTL, and EL TAGS This appendix describes how to create and modify JSP pages in JD.
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.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
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.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Chapter 5 Generating Dynamic Content. Creating a JSP Page A Sample JSP Page: easy.jsp JSP is Easy JSP is as easy as =
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.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
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.
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.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
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.
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.
Introduction Servlets and JSP
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Developing JavaServer Pages
Java Server Pages.
Scripted Page Web App Development (Java Server Pages)
Knowledge Byte In this section, you will learn about:
Invoking Java Code from JSP
MSIS 655 Advanced Business Applications Programming
Java Server Pages.
JSP Directives 1-Jan-19.
JSP implicit objects & directive elements
Presentation transcript:

Basic JSP Celsina Bignoli

Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped together! Problems: –good Java knowledge is needed to develop and maintain the application –changing look and feel or a new client type require changes to the Servlet code –cannot use web page development tools

Advantages of JSP separates request processing and business logic from the presentation –places all static HTML in a JSP page and adds a few JSP elements to generate the dynamic content allows the separation of tasks between Java programmers and WEB page authors makes it easier to change presentation without affecting business layer and viceversa

A Simple JSP Page Static: HTML/XML elements Dynamic: scriptlets Special JSP elements Example.jsp <% Date d=new Date(); String today = DateFormat.getInstance().format(d); %> Today is: HTML Scriptlet JSP tag

JSP Processing- Translation Phase Servlet Container JSP Page (.jsp) JSP Page (.jsp) Servlet Source (.java) Servlet Source (.java) JSP Translator Servlet Class (.class ) Servlet Class (.class ) Java Compiler JVM Translation Phase Request Processing Phase Text Buffer Text Buffer requestresponse

JSP Processing- Request Processing Phase Servlet Container JSP Page (.jsp) JSP Page (.jsp) Servlet Source (.java) Servlet Source (.java) JSP Translator Servlet Class (.class ) Servlet Class (.class ) Java Compiler JVM Translation Phase Request Processing Phase Text Buffer Text Buffer requestresponse

package jsp; import javax.servlet.*; import javax.servlet.http.*; … import java.text.*; import java.util.*; public class example_jsp extends org.apache.jasper.runtime.HttpJspBase { … } example_jsp.java extends: javax.servlet.http.HttpServlet JSP Translation - Example

public void _jspService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { … try { out = pageContext.getOut(); out.write(" \r\n"); Date d=new Date(); String today = DateFormat.getInstance().format(d); out.write("\r\n"); out.write("Today is:\r\n"); out.write(" "); out.print(today); out.write(" \r\n"); out.write(" "); } … } service() method - Example

JSP Elements Directives Comments Actions –standard actions –custom actions and JSTL Expression Language (EL) Scripting JavaBean components

JSP Directive Elements Specify attribute of the page itself –type of content –buffering requirements –resources used –how runtime errors should be handled Do not affect content of a response but how the container should handle it. Enclosed between Have a name and one or more attribute/value pairs –attribute and values are case-sensitive –values must be enclosed in single or double quotes

Page Directive other possible values for contentType –text/plain –text/xml –text/vnd.wap.wml other possible attributes –errorPage –isErrorPage –session –pageEncoding –buffer –autoFlush

Taglib Directive declares a JSTL custom tag library used in the page the prefix is the name used for the library in the JSP page the uri uniquely identifies the library

JSP Comments delimited by ignored when the page is processed never sent to the browser

JSP Actions represent dynamic actions to be performed at runtime action_body or allows dor actions in different libraries to have the same name allow contaienr to determine which library an action belongs

Standard Actions makes a java bean component available to a page gets a property value from a JavaBean components and adds it to the response Set a JavaBean property value Include the response from a servlet or JSP page during the request processing phase Forwards the processing of a request to a servlet or JSP page

Standard Actions (2) adds a parameter to a request handed over to another servlet or JSP page Used to run applets on the browser Set the value of an action attribute Sets the action element body Dynamically generate an XML element to encapsulate text “verbatim”

JSP Standard Tag Library (JSTL) group of libraries each containing related actions Core XML processing Internationalization Relational Database Access Functions

JSP Expression Language based on both ECMAScript and XPath built-in support for JavaBean access and manipulation, collection of objects, automatic type conversion etc… EL expressions enclosed within ${ and } ${anObject.aProperty} 10000}”> …

Scripting Elements fragments of java code embedded in a JSP page Declarations Expressions Scriptlets heavily used in early JSP pages but rarely in newer developments (and discouraged)

Declarations used to insert methods, constants and variable declarations in JSP pages <%! private static String EXAMPLE=“/example2”; private static String SHOP_PAGE=“/estore.jsp”; private static String CART_PAGE=“/shopcart.jsp”; private String dispPrice(String price) { // method body } %>

Expressions an embedded Java expression that is evaluated and converted to a text String The text string is placed in the JSP output at the location in which the element appears

Scriptlets used to include complete fragments of java code in a JSP page cau use the out implicit object (of type javax.servlet.jsp.JspWriter) to write output <% if (state.isLocal()) out.print(totalCost * localTax) else out.print(totalCost) %>

Problems with Scriptlets discouraged since they do not promote separation of presentation from data/logic look as a Servlet inside-out make JSP page as hard to write/maintain as corresponding Servlet

Model-View-Controller Design Separation of –data and business logic (Model) –data presentation (View) –data interaction (Controller) The user interacts with the Controller to ask for things to be done. Controller forward the request to the Model the result of the request is displayed by the View

Model-View-Controller Design Controller (Servlet) View (JSP) Model (JavaBean) Data Data Tier JSP/Servlet Container Request Response Browser