Java Server Pages Lecture 17 27 July 2013. Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)

Slides:



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

CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer 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.
Michael Brockway Application Integration JavaServer Pages l Introduction & Overview l Implicit Objects l Scripting l Standard Actions l Directives l References.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
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.
Integrating Servlets and JavaServer Pages Vijayan Sugumaran School of Business Administration Oakland University Parts of this presentation provided by.
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,
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 Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Java Servlets & Java Server Pages Brad Rippe Fullerton College.
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.
11. Java-Based Web: JSP, JSF. 2 Motto: Rule 1: Our client is always right Rule 2: If you think our client is wrong, see Rule 1. - Anonymous.
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.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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.
JSP Java Server Pages Softsmith Infotech.
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.
Jordan Anastasiade. All rights reserved.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
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.
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.
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 Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
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.
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
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.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
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.
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.
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.
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 ( )
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 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.
JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
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.
Apache Struts Technology A MVC Framework for Java Web Applications.
JSP Action Elements Lec - 37.
Java Server Pages By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Pre-assessment Questions
MSIS 655 Advanced Business Applications Programming
Introduction to Java Server Pages
Java Servlets & Java Server Pages
Introduction to Servlets
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.
Scripted Page Web Application Development (Java Server Pages)
Presentation transcript:

Java Server Pages Lecture July 2013

Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java) from its presentation (html) (???) JSP specification builds on the functionality provided by the servlet specification.

How do JSP’s Work Browser Servlet/JSP Server Generated Servlet index.jsp index.java compiles checks converts Forwards to

JSP Life Cycle

Basic JSP Syntax Contains html code like static html pages with the JSP tags and scripting included in the page. Three basic types of jsp tags Scripting Elements Directive Elements Action Elements

Scripting Elements Allow java code – variable or method declarations, scriptlet, and expressions. Declaration tag Scriptlet tag Expression tag

Declaration Tag Allows you to declare page wide variables and methods. Methods and variables have class scope Note, code must end with ; like any java code

Scriptlet Tag Used to include small pieces of Java code <% for(Enumeration e = beanList.elements(); e.hasMoreElements(); ) { UserBean uBean = (UserBean) e.nextElement(); out.println( uBean.getUserName() ); } %>

Expression Tag Accepts any Java expression, evaluates the expression, converts to a String, and displays. Short hand for:

JSP Directives Directives provide global information to the JSP engine For example, a directive can be used to import java classes. Directive elements have a syntax of the form

Page Directives The page directive defines a number of page dependent attributes page language=“Java” [ extends=“className” ] [ import=“importList” ] [ session= “true|false” ] [ buffer=“none|sizekb” ] [ autoFlush=“true|false” ] [ isThreadSafe=“true|false” ] … %>

Page Directive If language attribute is set, must be = “Java” Default import list is java.lang.*, javax.servlet.*, javax.servlet.jsp.* and javax.servlet.http.*. If session = “true” then default session variable of type javax.servlet.http.HttpSession references the current/new session for the page.

Include Directive The include directive is used to inline text and/or code at JSP page translation-time.

JSP Actions The syntax for action elements is based on XML(i.e. they have a start tag, a body, and an end tag). The JSP specification includes some action types that are standard. New action types are added using the taglib directive.

Standard Actions Web container implements these actions

Standard Actions Associates an instance of a bean to a variable to use with in the jsp page …

Standard Actions - useBean id – variable name to reference instance of class scope page – javax.servlet.jsp.PageContext Objects only accessible from within the page request ServletRequest Objects accessible in pages processing request where bean is created session – HttpSession Objects accessible from user session application – ServletContext Objects accessible in pages belonging to same application

Standard Actions - useBean Type (optional) Allows scripting variable to be cast to another type from implementation class, java casting rules apply. Class Fully qualified class name that defines the implementation of the object

Standard Actions - setProperty Sets the value of properties in a bean Use property=“*” to set all properties from the request

Standard Actions - setProperty Name Variable name as defined in useBean Property Name of the bean property Request Name of the request parameter (if omitted same name as bean property name) Value Value assign property (Performs necessary conversions)

Standard Actions - getProperty Gets the value of properties in a bean Name Variable name as defined in useBean Property Name of the bean property to retrieve

Bean Example Random JSP Test Next number is:

Bean Example package random; import java.util.*; public class NumberGenerator { Random rnd = new Random(); public int getNextInt() { return rnd.nextInt(); }

Standard Actions – jsp:include Allows you to include resources in the same context as the current page page: Relative url flush: If true, buffer is flushed

Standard Actions – jsp:forward Allows you to dispatch the request to a different page page: Relative url

Standard Actions - Creates HTML that contains OBJECT or EMBED constructs that result in Java Plugin download and execution of Applet Can’t display applet Fallback is used if the plugin cannot be started

Standard Actions - jsp:param Used to provide key/value information for,, and Name and value are mandatory

Access Models Two approaches to building application with JSPs Model 1: JSP page processes all input Model 2: Servlet acts as a controller and directs http traffic to appropriate responses

Model 1 JSP is responsible for processing incoming requests and replying to clients All data access is through beans browserJSP BEAN Database

Model 1 Suitable for simple applications Easier to understand May lead to lots of Java code embedded within JSP pages for complex applications (I’ve never used this model???)

Model 2 Combine use of servlets and JSP Servlet acts as controller, JSP as presentation layer browser servlet JSP Beans Database

It’s a rap! JSP aren’t total separation of logic from the presentation. Although it’s a good start. Look into Custom tags to encapsulate your application logic and move it outside of the jsps. Creation of your own custom tag libraries help to eliminate java code from being embedded in the jsp. Frameworks like WebMacro, Struts, and Velocity provide additional features to

Resources Tomcath Struts Apache J2EE Web Site Servlet 2.3 Spec JSP 1.2 Spec Free Development space for jsps/servlets Lecture available at

Resources J2EE Developer’s Guide – ocs/guides/ejb/html/DevGuideTOC.html ocs/guides/ejb/html/DevGuideTOC.html J2EE Tutorial – fcs/index.html fcs/index.html Server Side Programming –