JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►

Slides:



Advertisements
Similar presentations
JSP and Servelets.
Advertisements

CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
JavaServerPages Some examples. About JSP Java server pages are a combination of html (or xml), java code appearing within tagged regions, and structures.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
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.
Generate Dynamic Content On Cache Server Master’s Project Proposal by Aparna Yeddula.
JSP Java Server Pages Reference:
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Web Development in Java Andrew Simpson. Overview Background Language Details Java Server Pages (JSP) Servlets Database Connectivity (JDBC) Samples and.
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Server-side Technologies
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Development Platforms Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
1 Chapter 2 The Web Tier  Web Applications and Web ContainersWeb Applications and Web Containers  Dynamic Content CreationDynamic Content Creation 
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.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
Java Servlets and Java Server Pages Carol Wolf Computer Science.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
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.
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.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
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.
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
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.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
JSP Custom Tags. Prerequisites Servlet API Mapping to JSP implicit objects JavaServer Pages Basic syntax Implementation via servlet API XML.
Java Servlets and Java Server Pages Norman White Stern School of Business.
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.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java Servlets and Java Server Pages
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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 Custom Tag Library Chengyu Sun California State University, Los Angeles.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Java Server Pages.
Servlets and Java Server Pages
Presentation transcript:

JavaServer Page by Antonio Ko

Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ► Tag Library ► Conclusion

Introduction ► Java Server Pages (JSP) is basically Sun's answer to Microsoft's Active Server Pages (ASP). ► Advantages over other technologies:  It is in Java  No tied to a particular server product ► JSP is actually based on Java Servlet

What is Servlet ► Java’s answer to the Common Gateway Interface (CGI). ► Applet: a java program that runs within the web browser. ► Servlet: a java program that runs within the web server.

What can Servlets do  Search Engines  Personalization Systems  E-Commerce Applications  Shopping Carts  Product Catalogs  Intranet Applications  Groupware Applications: bulletin boards, file sharing, etc.

Servlets vs JSP  Servlets  code looks like a regular Java program.  JSP  embed Java commands directly within HTML  Let’s examine a Servlet program next to a JSP program…  Each of these prints, “Hello, World!”

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(" "); out.println(" Hello World "); out.println(" "); out.println(" Hello World "); out.println(" "); }

Hello, World JSP Example Hello, World! The current time in milliseconds is

Syntax ► Three main types of JSP constructs embed in a HTML page:  Scripting elements  Directives  actions

Scripting Element ► Three forms available: 1., for output 2., for a block of Java code 3., for declaration

Directives ► A JSP directive affects the overall structure of the servlet that results from the JSP page. ► Syntax: ► Syntax: ► Three types of directives: 1.page 2.include 3.taglib

Action ► JSP actions are XML tags that invoke built-in web server functionality.  e.g. <jsp:setProperty name = “myBean” property = “message” value = “This is my message” />

Sample1 Untitled Document

Sample2 Untitled Document Have a nice day Have a lousy day

Sample 3 <%! Date theDate = new Date(); Date getDate() { System.out.println( "In getDate() method" ); return theDate; } %> Hello! The time is now

JavaBean ► An object that holds data with setter and getter methods. ► Can be used to store data through out the session. public class SimpleBean { private String message = "No message specified"; public String getMessage() { return(message); } public void setMessage(String message) { this.message = message; }

Tag Library ► One of the features of JSP ► Simplify complex server-side behavior into simple elements ► Creates custom JSP tags into a library. ► Each tag library has a tag library descriptor  TLD describes each tag information ► Hide underlying implementation

Tag Example Get Name and Course with DropList tag

// This is myTagExample.java package tony; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; import java.io.IOException; /** * SimpleTag handler that prints "Hello, world!" * SimpleTag handler that prints "Hello, world!" */ */ public class myTagExample.java extends SimpleTagSupport { protected String name=""; protected String name=""; protected String lastName=""; protected String lastName=""; public void doTag() throws JspException, IOException { public void doTag() throws JspException, IOException { getJspContext().getOut().write(name+ " :Hello world: “ +lastName); getJspContext().getOut().write(name+ " :Hello world: “ +lastName); } public void setName(String name){ public void setName(String name){ this.name = name; this.name = name; } public void setLname(String lname){ public void setLname(String lname){ this.lastName = lname; this.lastName = lname; }}

Tag Library Descriptor <tag><name>tagExample</name> tony.myTagExample tony.myTagExample EMPTY EMPTY perform name name true true lname lname true true

Conclusion