Chengyu Sun California State University, Los Angeles

Slides:



Advertisements
Similar presentations
Java Server Pages (JSP)
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.
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.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
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 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.
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.
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.
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.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
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:
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
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.
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.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
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.
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.
Web Technologies Java Beans & JSP By Praveen Kumar G.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
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 ( )
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.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
JSP java server pages.
CS3220 Web and Internet Programming Introduction to Java Servlets
Developing JavaServer Pages
Scripted Page Web App Development (Java Server Pages)
CS5220 Advanced Topics in Web Programming Course Overview
Invoking Java Code from JSP
MSIS 655 Advanced Business Applications Programming
JSP Syntax.
Java Server Pages.
Java Server Pages (JSP)
CS320 Web and Internet Programming Java Beans
CS320 Web and Internet Programming MVC Architecture
COP 4610L: Applications in the Enterprise Spring 2005
CS3220 Web and Internet Programming Introduction to Java Servlets
JSP implicit objects & directive elements
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
COSC 2956 Internet Tools Java Server Pages.
CS5220 Advanced Topics in Web Programming Course Overview
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Chengyu Sun California State University, Los Angeles CS320 Web and Internet Programming JSP Scripting Elements and Directives Chengyu Sun California State University, Los Angeles

Java Server Page (JSP) Why? How? It’s tedious to generate HTML using println() Separate presentation from processing How? Java code embedded in HTML documents

HelloJSP1.jsp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>Hello JSP 1</TITLE></HEAD> <BODY>A JSP without J or S.</BODY> </HTML>

HelloJSP2.jsp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>JSP Hello World</TITLE></HEAD> <BODY>Hello World on <%= new java.util.Date() %>. </BODY> </HTML>

How Does JSP Work? convert compile execute JSP Servlet ByteCode automatically done by server Look under $TOMCAT_HOME/work/Catalina/localhost/context_name

Eclipse Work Directory $WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 Or tmp1, tmp2, … if you created multiple server runtimes in Eclipse

Some Simple Observations about the JSP/Servlets HttpJspBase is a subclass of HttpServlet _jspService() handles everything replaces service() in HttpServlet What happened to doGet(), doPost(), ...?? HTML text  out.write(...)

JSP Components HTML template text Code elements of Java Directives Comments Scripting elements Beans Expression language Custom tag libraries

Directives <%@ type attr=“value” ... %> Three types of directives page include taglib

Some Page Directives <%@ page import=“java.util.*, java.util.zip.*” %> <%@ page contentType=“text/html” %> <%@ page pageEncoding=“Shift_JIS” %> <%@ page session=“false” %> <%-- default is true --%>

Comments <%-- Hidden Comments --%> <!-- Output (HTML) Comments -->

JSP Scripting Elements JSP Expression JSP Scriptlet JSP Declaration

Elements of a Programming Language Comments Literals Variables and Types Operators Expressions: anything that evaluates to a single value Statements Functions Classes Packages

JSP Expressions <%= Java expression %> <%= expression %> in JSP out.write( expression ) in _jspService()

Example: Add.jsp Add two integer parameters and display the sum

Pre-defined Variables request, response, out session, application config, pageContext page The same request, response, session etc. that are used in servlets – see the Servlet API documentation for what you can do with them.

JSP Scriptlets <% Java code %> All code goes inside _jspService()

Example: Add.jsp Again Add the code to validate the parameters

Another Scriptlet Example <% if( Math.random() < 0.5) { %> <H1>Have a <I>nice</I> day!</H1> <% } else { %> <H1>Have a <I>lousy</I> day!</H1> <% } %>

JSP Declarations <%! class variables or methods %> All code goes outside _jspService()

Example: RequestCounter.jsp Initialize a counter as a class variable Increment the counter each time the JSP is requested

About JSP Scripting Elements … JSP Expression JSP Scriptlet JSP Declaration There is a straightforward mapping between JSP with scripting elements and servlet

… About JSP Scripting Elements Mixing presentation and processing Hard to read, debug, or maintain No clean and easy way to reuse code Do NOT use them