 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.

Slides:



Advertisements
Similar presentations
Michelle Johnston, Firebird Services Ltd
Advertisements

Java Script Session1 INTRODUCTION.
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.
Apache Struts Technology
 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.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
DT211/3 Internet Application Development
DT211/3 Internet Application Development
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.
Comp2513 Java Server Pages Daniel L. Silver, Ph.D.
Q: According to Intel, the Pentium conforms to the IEEE standards 754 and 854 for floating point arithmetic. If you fly in aircraft designed using a Pentium,
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.
CSCI 6962: Server-side Design and Programming History and Background.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
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.
JSP Java Server Pages Softsmith Infotech.
Introduction to Java Server Pages (JSPs) Robert Thornton.
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)
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
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.
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 Presented by K.Venkata Ratnam HOD MCA (Dept) Newton’s Institute of Engineering.
DAT602 Database Application Development Lecture 16 Java Server Pages Part 2.
Chapter 7 Being a JSP. JSP introduction JSP is a solution for two issues  Servlet is difficult for HTML designers since they may not know Java  Formatting.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
1 Java Server Pages Allows the embedding of Java commands in a page of HTML. Popular for UI heavy solutions. These commands are then interpreted by a JSP.
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.
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.
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
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.
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.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
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 ( )
Java Servlets and 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.
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 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.
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.
JSP java server pages.
JSP Based on
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.
Scripted Page Web App Development (Java Server Pages)
Java Server Pages (JSP)
Java Server Pages B.Ramamurthy.
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.
Presentation transcript:

 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy (and may violate OaOO)  Keep the embedded Java simple  Use external helper classes (Beans?)

JSP Document.java file.class file.class file ready to run Response Document Translation Compilation Reinitialization Subsequent User Requests

 A JSP page is translated into a Java Servlet  And then compiled  On Tomcat, the compilation happens the first time a page is requested  First request can be very slow!  Afterwards, just as fast as a Servlet (because it is then a servlet)

Hello JSP Hello World:

 This extract shows the part that produces the output – compare it with the JSP: out = pageContext.getOut(); _jspx_out = out; out.write(" \r\n"); out.write(" "); out.write(" Hello JSP "); out.write(" "); out.write(" \r\n"); out.write(" Hello World:\r\n "); out.print( new java.util.Date() ); out.write("\r\n");

 So far we’ve seen literals:  E.g.  Copied straight to output (to browser)  And expressions:  E.g.  Return a value included in the output  Also have:  Directives, Declarations and Scriptlets

 Instructions to the compiler  Examples:  Include another page (compile-time)  What is the difference ???  Import some Java packages (comma sep.) 

 These are tags that start with the word jsp as in the previous example  These are mainly for handling form beans as will be shown later apart from 3 tags.  <jsp:forward, to forward user to another page   <jsp:plugin, to import plugin as a java applet in the client browser.   <jsp:include, to include the result of a jsp page

 Used to declare variables and methods  Go in the declaration section of the Servlet  Can then be used later in the JSP page  Note the syntax  Examples: 

 These are sections of Java code embedded in the page  Unlike expressions, they do not return a value  But may write directly to the page  Get the writer: response.getWriter()  They go in the service method of the servlet  Get executed each time a page is requested

 Demonstrates much of the above Page accessed: times <% if ( (n % 10) == 0 ) { n = 0; } %>

 Application  Config  Out  Request  Response  Session

 Each JSP page has access to two special objects  The Request object carries information passed by the HTTP request (e.g. made by the browser)  This includes any submitted form data  The Response object is used to pass information back to the Client (browser)  E.g. response.getWriter() provides an output stream for direct writing to the client

 JSP makes form handling easy  Can use request.getParameter() to get submitted values  Or can define a JavaBean to grab the values semi-automatically.  We’ll see this in action later with a simple example

 Global object: request, session Thanks for giving us your name,

 The form can specify whether data is supplied via a GET or POST request  POST is the usual way  Therefore, a servlet should implement the doPost() method to process a form  JSP hides these GET/POST details (see request.getParameter and )

 Helper classes for servlets  To generate forms (+ other HTML)  Process the form input  JSP + JavaBeans (more later)  JSP + Tag Library (will be covered later)

 Come in two types  Simple (this course)  Enterprise (EJB: more complex, not covered)  Simple JavaBeans  Data bound classes  Define properties (fields)  Define get/set methods  See following example

Welcome to the Hotel California Name: How many nights: 1 2 3

Bean test to stay for nights.

<jsp:useBean id='roomBooking' scope='page' class='beans.HotelBean' /> Bean test to stay for nights.

package beans; public class HotelBean { String name; int nNights; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getnNights() { return nNights; } public void setnNights(int nNights) { this.nNights = nNights; }

 Note the setting: scope='page'  Scope has four possible settings:  Page  Bean exists for execution of that page only  Request  Like page, but survives any forward or include requests

 Session  The Bean exists for multiple requests within the web application, from a particular web browser instance  Used for shopping baskets etc.  Application  The Bean exists for all requests from all users, for all pages that use it.  Survives until the Web Application Server is restarted  Can be used for a database connection (or connection pool)

 For this example, consider the differences:  JavaBean JSP page: more complex  JavaBean also required an external class definition  Discussion question:  When would JavaBean solutions be better than manual versions?  Answer:

<%! Date theDate = new Date(); Date getDate() { return theDate; } %> Hello! The time is now

 The JSP can get really intractable with lots of scriplets  A direct example of using scriplet is a for loop to display records from a database in a table format.  Put the code for the view in a function and call it as much as you need

<% public void printRecord(int Number){ out.print(“ ”); out.print(“ Number ”); out.print(“ ” +Number+“ ”); out.print(“ ”); } %> <% for ( int i = 0; i < n; i++ ) { printRecord(i+1); } %>

 This doesn’t look anymore like an HTML code.  What is the point of JSP then, is it to get messy code!!  So, sun devised a remedy for that and the final result looked really good, but not the development  The solution is called JSP Standard Tag Library or JSTL.  The last example will be written in one tag as

 Next Lecture