Scripted Page Web App Development (Java Server Pages)

Slides:



Advertisements
Similar presentations
Apache Struts Technology
Advertisements

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.
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.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
Comp2513 Java Server Pages Daniel L. Silver, Ph.D.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
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.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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.
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.
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.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
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.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Java Server Pages (JSP) Provide a cross-platform framework for creating dynamic web contents JSP Components: Static HTML/XML parts Special JSP Tags Snippets.
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.
Java Server Pages (JSP)
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
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.
© 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.
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
JAVA SERVER PAGES -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
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,
Chapter 14 Using JavaBeans Components in JSP Documents.
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.
Java Server Pages Can web pages be created specially for each user?
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.
Java Server Pages (JSP)
Java Server Pages By: Tejashri Udavant..
COMP9321 Web Application Engineering Semester 2, 2017
Scope and State Handling in JSPs
Web Software Model CS 4640 Programming Languages for Web Applications
Pre-assessment Questions
MSIS 655 Advanced Business Applications Programming
Introduction to Java Server Pages
Introduction to Java Bean
Java Server Pages (JSP)
Java Server Pages B.Ramamurthy.
CS320 Web and Internet Programming Java Beans
JavaScript CS 4640 Programming Languages for Web Applications
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)
Web Technologies Java Beans & JSP
Presentation transcript:

Scripted Page Web App Development (Java Server Pages) Upsorn Praphamontripong CS 4501-006 Design and Implementation of Software for the Web Fall 2016

Web Applications A web application uses enabling technologies to review Web Applications A web application uses enabling technologies to make web site contents dynamic allow users of the system to implement business logic on the server Web applications allow users to affect state on the server An enabling technology makes web pages interactive and responsive to user inputs CS 4501-006

Server Side Processing review Server Side Processing data HTTP Request Apache Tomcat Client UI implemented in a browser Server Web server Container engine Program components HTTP Response HTML CS 4501-006

review What We Will Study HTML CSS JS Servlets Ajax JSPs CS 4501-006

Enabling Technologies – Plug-in Scripted Pages review Enabling Technologies – Plug-in Scripted Pages Scripted pages look like HTML pages Execution is on the server, not on the client They have HTML with program statements that get and process data JSPs are compiled and run as servlets PHP scripts are interpreted within the server Scripted pages are generally easy to develop and deploy They mix logic with HTML -- can be difficult to read and maintain CS 4501-006

Java Scripts and Java Servlets review Java Scripts and Java Servlets Java Scripts provide client-side execution ability Interpreted Cumbersome and error prone Non-portable Java Servlets provide server-side execution Compiled Portable Robust Mixes static (HTML) with dynamic (business logic) “Java that creates HTML” HTML in Java CS 4501-006

Java Server Page (JSP) JSP is a server-side technology that support dynamic content JSPs turn servlets “inside-out” JSPs are translated to servlets, compiled, then executed This encourages separation of tasks Java in HTML App Development Java, JavaBeans Java programmer Integration w/ JSP Web Java programmer Page Layout Graphics designer Writing HTML ? Help developers insert java code in HTML by making use of special JSP tags, most of which start with <% and end with %> JSPs = text files combining HTML and embedded JSP actions and commands CS 4501-006

What we can do with JSPs Collect input from users through web forms Retrieve information from some data sources Present information retrieved from some data sources Create web pages dynamically Social networking system And so much more CS 4501-006

Why use JSPs Built on top of Java servlets API Has access to Java APIs Can be used in combination with servlets Servlets handle the business logic JSPs deal with the front page CS 4501-006

Why use JSPs HTML JavaScript Servlet JSP Cannot dynamically create information JavaScript Generate HTML dynamically on the client Cannot perform complex tasks (such as accessing and retrieving information from a database) Servlet Rely on println() to generate HTML document Hard to develop / read / maintain JSP Generate HTML dynamically on the server Can perform complex tasks Simply to write / read / maintain CS 4501-006

JSP execution – mental model of JSP developer JSP Processing hello.jsp 2. Read Server with JSP container http://localhost:8080/cs4501/hello.jsp 1. Request Web client 5. Response 3. Run JSP 4. Response JSP execution – mental model of JSP developer CS 4501-006

JSP Processing JSP execution – actual implementation Server with hello.jsp Server with JSP container 2. timestamp 2. if no hello.class or hello.jsp newer than hello.class 1. request Yes Web client 3. Translate 6. response hello.java 2. timestamp No 4. Compile 5. Execute hello.class JSP execution – actual implementation CS 4501-006

JSP Life Cycle jspInit() Initialization Request _jspService() Main logic _jspService() Response Similar to servlet life cycle Destruction jspDestroy() CS 4501-006

JSP Elements JSP syntax: <% x … %> where x is one of the following @ Directive : Global information for page Language, import statements, etc. Scripting Elements : Java code ! Declarations : Class level variables and methods (blank) Scriptlets : A block of Java code Can make external calls = Expressions : Values to be printed Actions : To modify runtime behavior CS 4501-006

(1) JSP Directives Information sent to the JSP container <%@ page attribute=value … %> Page attributes are listed in book You will usually use the defaults <%@ include <filename> %> File inserted into the JSP inline before JSP is compiled <%@ taglib uri=“tagLibURI” prefix=“tagPrefix” %> Declare a tag library used in the JSP CS 4501-006

(2) JSP Scripts – Declarations Java code to define class-level variables and methods <%! int Sum = 0; private void AddToCount (int X) { // To be called from a scriptlet Sum = Sum + X; } %> jspInit() and jspDestroy() can also be defined here to initialize and clean up state CS 4501-006

(2) JSP Scripts – Scriptlets Blocks of general Java code Placed in _jspService() by translator Can access variables from JSP Declarations Scriptlets can access servlet objects request : HttpServletRequest object response : HttpServletResponse object out : for printing Must use the name “request” <% String nameVal = request.getParameter (“LASTNAME”); out.println (nameVal); %> CS 4501-006

(2) JSP Scripts – Expressions Abbreviated scriptlet print statement <p> The user’s last name is <%= nameVal %> </p> Expression is evaluated and turned into a string CS 4501-006

(3) JSP Actions Tags to change the behavior of the JSP Action types: <jsp: include> <jsp: useBean> <jsp: setProperty> <jsp: getProperty> <jsp: forward> <jsp: param> <jsp: plugin> CS 4501-006

(3) JSP Actions – Include <jsp:include> can be used to include either a static or dynamic resource Static A static file is loaded inline into the JSP before translation and compiling The same content is included every time Dynamic : A web software component is run and the results are included as part of the response A dynamic include can result in different content each time CS 4501-006

(3) JSP Actions – Include Static <jsp:include page=“copyright.html” /> Dynamic : <jsp:include page=“myjsp.jsp” flush=“true” /> myjsp.jsp is compiled myjsp.jsp is executed Output from myjsp is included in the current JSP Current output is flushed before myjsp is included CS 4501-006

(3) JSP Actions – Java Beans A Java Bean is a Java class with 3 characteristics: public class public constructor with no arguments public get and set methods (called getters and setters) Property : A special, simple data object (that is, variable) getName () … <jsp:getProperty> setName (String name) … <jsp:setProperty> Note that a bean is not a Java language feature, but a design convention (pattern) CS 4501-006

(3) JSP Actions – Java Beans useBean causes a JavaBean object to be instantiated useBean gives a name to the new object (id=) useBean defines the scope useBean declares the location (bean details) CS 4501-006

(3) JSP Actions – Java Bean Example Syntax for using a bean Note: scope=“application” allows Beans to be shared among different servlets – DON’T USE IT! Lead to interactions among each other … more later … Converts to Java import statement, Java 4 requires all imports to be packages <%@ page import=“jspexamples.*” %> <jsp:usebean id=“letterColor” class=“AlphabetCode” scope=“page” /> ID name to use for object (AlphabetCode LetterColor = new … ) Name of class JSPs offer several useful scopes for variables … CS 4501-006

(3) JSP Actions – Properties setProperty gives a value to a property in a bean <jsp:setProperty name=“langBean” property=“language” value=“Java”/> Equivalent to the call: langBean.setLanguage (“Java”); <jsp:setProperty name=“langBean” property=“*” /> Sets all of the properties with values from HTML form getProperty retrieves the value of a property <jsp:getProperty name=“langBean” property=“language”/> Equivalent to the call: langBean.getLanguage(); CS 4501-006

(3) JSP Actions – Properties Case of property name is very important Property must begin with a lower case letter (“language”) Getters and setters must have the property name start with a capital letter ( setLanguage(), getLanguage() ) CS 4501-006

(3) JSP Actions – Java Bean Summary Using Java Beans increases separation between the HTML and Java The Beans / Property pattern provides a convenient standard for implementing standard Java classes JSP’s useBean uses Java reflection to translate property names (for example, “language”) to method calls that are assumed to exist (“setLanguage()” and “getLanguage()”) The bean does not have to have an object with the name of the property, as long as it has a getter or setter CS 4501-006

(3) JSP Actions – Forwarding jsp:Forward sends a request to another JSP on the same server Similar to a method call, but no return <jsp:forward page=“anotherPage.jsp” /> When this statement is reached, execution will jump to the JSP anotherPage.jsp Use as a front-end when we need to decide which JSP to execute based on some input data Use to authenticate users (see student info system example) CS 4501-006