CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

Internet i jego zastosowania 1 J2EE Servlets. Internet i jego zastosowania 2 Agenda Overview Servlet Interface Servlet Context Request Response Sample.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
6 Copyright © 2005, Oracle. All rights reserved. Using Advanced Techniques in Servlets.
JSP and Servelets.
M-V-C for web applications. Model for Web Applications model consists of data and system state database tables –persistent data session information –current.
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
Cookie in a servlet. Cookies are small bits of textual information that a Web server sends to a browser and that the browser returns unchanged when visiting.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Apache Tomcat as a container for Servlets and JSP
Java Server Pages (JSP)
Java Servlets Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
JSP Java Server Pages Reference:
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,
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
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.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Introduction Servlets and JSP Celsina Bignoli
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Chapter 11 © 2005 by Addison Wesley Longman, Inc Overview of Servlets - A servlet is a compiled Java class - Servlets are executed on the server.
Java Servelets. What Is a Servlet? A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Objectives Java Servlet Web Components
CSC 2720 Building Web Applications
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.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets & Java Server Pages Lecture July 2013.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Java Servlets and Java Server Pages Norman White Stern School of Business.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
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.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Java Servlets Java Server Pages (JSP)
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Java Servlets and Java Server Pages
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 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,
1 Servlets – Part 2 Representation and Management of Data on the Web.
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.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Chapter 26 Servlets.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

CGI programming

Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed to standard input (STDIN) script outputs to standard output (STDOUT) output is http response message

CGI Environment Web Server defines –working directory –preset variables –filehandles (links to resources on the server) CGI script must produce –minimal set of response headers e.g. Content-Type: text/html –content of http response

Environment Variables provide info about the web server and the client information drawn from http request headers SERVER_NAME REMOTE_ADDR CONTENT_LENGTH CONTENT_TYPE

Server-Script interface STDIN –Web server launches CGI program and provides standard input STDOUT –CGI program outputs response to web server STDERR –Web server handles CGI program error output –Apache appends it to error log

CGI Output headers: –Content-Type print Content-Type:text/html\n\n; –Location print Location:someFile.html\n\n; –Status print 503 Service unavailable;

CGI Example

Ice Cream Stand Design Browser Web Server CGI Script Present order form and response Handle request and response Produce order form Process order form

CGI script design Input –Form data Output –Order form –Order response Self-referencing form

ice cream stand CGI script

CGI is programmer-oriented HTML embedded in the program HTML generated as a series of function calls requires –knowledge of HTML tags –programming skills

Does CGI implement M-V-C? No! Data processing (model) is inseparable from response page generation (view) Also contains elements of controller –Handles request headers and creates response headers

CGI security problems scripts can be corrupted by user data –hidden fields –arbitrary commands embedded in text fields file permissions file locations trust relationships between web server and other machines

speed of CGI each request creates a new process overhead of communication through CGI overhead of interpretation and compilation Possible solutions (only partly effective) –code optimisation –Fast CGI –mod_perl with Apache

Alternatives to CGI Java servlets JSP - Java Server Pages PHP ASP - Active Server Pages Coldfusion

Java Servlets

Servlets add functionality to a web server comparable to CGI –More tightly defined –Separate http handling from middleware –Deployed in a web container (see later) vendor and platform independent (Java) integrate with other Java technologies –J2EE framework

Servlets efficient –permanently available, no compile overhead robust –encapsulation, type-checking, error handling secure –specialised interfaces to other server resources that are not vulnerable to attack

Servlets implement javax.servlet.Servlet interface public void init(ServletConfig c) run on initialisation public void service (ServletRequest req, ServletResponse res) runs for each request and response public void destroy () end of servlet life

Web Server Servlet Class init(ServletConfig c) service(ServletRequest r, ServletResponse s) destroy() once at first request or at server start every request once when server shuts down webcontainer

HTTP servlets Most commonly used servlet subclass –javax.servlet.http.HttpServlet implements additional methods to handle http functionality service() method passes handling to more specific sub-class methods –doGet, doPost …

The Hello World servlet import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet{

The Hello World servlet public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType(text/html); Printwriter out = res.getWriter();

The Hello World servlet out.println ( ); out.println (Hello World); out.println ( ); out.println ( Hello World ); out.println ( ); }

Servlets vs CGI similar idea –web container like CGI environment –request and response objects vs std I/O servlet compilation once only –much faster, even though run in JVM security problems greatly reduced –web container is much more secure but still HTML embedded in code

Java Server Pages

Java Server Pages (JSP) Template for page generation Separates code from HTML HTML with additional jsp tags processed on server side links to other Java entities for more complex processing/ database access platform independent

JSP elements A JSP is a template for generating a web page –Response to an http request JSP elements are tags embedded in HTML JSP scripting elements –Specify Java code to be run when template is requested –Separate the coding from HTML content Fits with M-V-C philosophy

JSP Digital Clock Date and Time Simple JSP Example

JSP scripting elements Three different kinds of scripting, determining when each is executed: Insert snippets of Java code embed a code expression, which evaluates in the response (no ;) declare variables and methods

Examples

result

JSP and Servelets

How does JSP work? NOT a Java scripting language NOT like php –JSP are NOT parsed on request Java code must involve classes, creation of objects, etc… JSP is a designer-friendly way of writing servlets

Clock example

Server with Tomcat Web Container client translation request processing GET clock.jsp 1 clock.jsp read 2 Servelet clock.java generate 3 clock.class compile and deploy 4 execute 5 http response 6

public class clock implements Servlet { public void service (ServletRequest r, ServletResponse s) throws ServletException, IOException { s.setContentType (text/html); PrintWriter out = s.getWriter (); out.println ( ); out.println ( JSP… ); out.println ( );

out.println ( Date and Time ); out.println (new java.util.Date.toString()); out.println ( ); }

JSP directive elements applied when the JSP is compiled into a servelet –Only executed once (on compilation) –Do not affect the response Used to set up resources such as –Java classes –inclusions

JSP directive elements specify page information (static) scripting language, error page includes a file, e.g. an applet declare a tag library (custom actions)

JSP and http

A JSP is a servelet Permanently resident in server memory Multi-threaded Request and response objects Sessions and cookies

Accessing request information Methods of the request object provide all request information object is called request public String getParameter (String name) public String getMethod () public String getHeader (String name) public Cookie [] getCookies ()

javax.servelet.http.Cookie class getName () –the name of the cookie getValue(), setValue (String value) –gets/sets the value of a cookie getDomain(), setDomain(String dName) –get/set the cookie domain name getPath(), String setPath(String path) –get/set the request path the cookie is associated with getMaxAge(), setMaxAge (int expiry) –get/set maximum age for the cookie

javax.servelet.http.HttpSession provides standard functionality for handling sessions handles cookies as standard but must be extended to handle URL rewriting holds client state info resident in memory –automatically times out abandoned sessions created/returned by HttpServeletRequest class getSession method

JSP and Java Beans

Java Beans ordinary Java classes with the following properties: –introspection –customization –events –properties –persistence

Java Beans introspection –an analyser can inspect how the Bean works properties –naming conventions for getter and setter methods persistence –implement the Serializable interface –Bean state can be stored

Example Java bean public class ExampleBean implements java.io.Serializable { private String name = null; private int score = 0; public ExampleBean() {} // Empty constructor /* Getter and Setter Methods */ public String getName() { return name; } public void setName(String s) { name = s; }

Example Java bean public int getScore() { return score; } public void setScore(int i) { score = i; } /* No method required to implement Serializable */ }

JSP action elements action elements –perform an action when page is requested uses a JavaBean component property from JavaBean used in the page sets a JavaBean property (possibly using request information)

<jsp:useBean id="userInfo" class="com.ora.jsp.beans.userInfo. UserInfoBean > <jsp:setProperty name = userInfo property = userName value = Gandalf />

The following information was saved: User Name: <jsp:getProperty name="userInfo" property="userName"/> Address: <jsp:getProperty name="userInfo" property=" Addr"/>

Other JSP action elements responses from other jsp pages or servelets forwards processing to other jsp or servelet passes a parameter with include or forward generates the HTML to embed an applet

Timetable change From 10 November: Two lectures moved into one slot: –Wednesday 11-1 –B39 –(lab with GE being moved) Labs will still be Thursday, 9-11