web week-1.b introduction to web programing

24
7/28/2019 WEB Week-1.B Introduction to Web Programing http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 1/24 INFO-3303 Web Programming-II Introduction to Web Programming  Week 1-B by Zeeshan Bhatti Department of Information Science KICT-IIUM

Upload: pyong-pyaa

Post on 03-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 1/24

INFO-3303 Web Programming-IIIntroduction to Web Programming

 Week 1-B

by 

Zeeshan Bhatti

Department of Information Science

KICT-IIUM

Page 2: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 2/24

Java Servlet Java servlets are a key component of server-side Java

development.

 A servlet is a small, pluggable extension to a server thatenhances the server’s functionality. 

Servlets allow developers to extend and customize any  Java-enabled server—a web server, a mail server, anapplication server, or any custom server— with ahitherto unknown degree of portability, flexibility, andease.

Page 3: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 3/24

Introduction to Common Gateway Interface (CGI) The Common Gateway Interface, normally referred to as

CGI, was one of the first practical techniques for creatingdynamic content.

Is a specification for transforming information between www server and CGI program

 A CGI program is any program designed to accept andreturn data that conforms to the CGI specification

CGI program could be written in any programminglanguage including C , Perl, Java or VB

CGI are most common ways for web servers to interactdynamically with users

Page 4: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 4/24

 

The CGI life cycle 

Page 5: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 5/24

Fast CGI A company named Open Market developed an

alternative to standard CGI named FastCGI.

In many ways, FastCGI works just like CGI—theimportant difference is that FastCGI creates a singlepersistent process for each FastCGI program.

Page 6: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 6/24

PerlEx   PerlEx, developed by ActiveState, improves the

performance of CGI scripts written in Perl that run on Windows NT web servers.

PerlEx uses the web server’s native API to achieve itsperformance gains.

Page 7: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 7/24

Active Server Pages Microsoft has developed a technique for generating

dynamic web content called Active Server Pages, orsometimes just ASP.

 With ASP, an HTML page on the web server cancontain snippets of embedded code (usually VBScriptor JScript—although it’s possible to use nearly any 

language). This code is read and executed by the web server

before it sends the page to the client. ASP is optimizedfor generating small portions of dynamic content.

Page 8: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 8/24

Now … Java Servlet  A servlet is a generic server extension.

 Java class that can be loaded dynamically to expand

the functionality of a server. Servlets are commonly used with web servers, where

they can take the place of CGI scripts.

 A servlet is similar to a proprietary server extension,

except that it runs inside a Java Virtual Machine (JVM)on the server, so it is safe and portable.

Page 9: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 9/24

Servlets They are programs that run on web server acting as a

middle layer between a request coming from a Webbrowser or other HTTP client and databases or

applications on the HTTP server. Their job is to:1. Read any data sent by the user.

2. Lookup another information about the request that isembedded in the HTTP request 

3. Generate the results.4. Format the results inside a document

5. Set the appropriate HTTP response parameters

6. Send the document back to the client 

Page 10: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 10/24

Unlike CGI and FastCGI, which use multiple processesto handle separate programs and/or separate requests,servlets are all handled by separate threads within the web server process.

Page 11: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 11/24

This means that servlets are also efficient and scalable.

Because servlets run within the web server, they can

interact very closely with the server to do things thatare not possible with CGI scripts.

Page 12: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 12/24

Advantages of Servlets over

traditional CGI Java Servlets are more:

efficient

easier t0 use powerful

portable

safer and

cheaper than traditional CGI and many other alternativeCGI-like technologies.

Page 13: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 13/24

Advantages of Servlets over

traditional CGI Efficient

 With CGI a new process is started for each HTTP request. If CGIprogram itself is short, the overhead of starting the process candominate the execution time.

 With servlets, the Java virtual machine stays running and handleseach request using light weight Java thread, not a heavyweightoperating system process.

Similarly in CGI for N simultaneous request to the same CGOprogram , the code for CGI program is loaded into memory N times

 With servlets, however, there would be N threads but only a single

copy of the servlet class.  When CGI program finishes handling request, the program

terminates – servlets however, remain in memory even after they complete a response, so it is straightforward to store arbitrary complex data between request.

Page 14: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 14/24

Advantages of Servlets over

traditional CGI Convenient

Servlets have extensive infrastructure for automatically parsing and decoding HTML form data, reading andsetting HTTP headers, handling cookies, trackingsessions and other high level utilities.

Reusable codes make servlets flexible than CGI.

Page 15: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 15/24

Advantages of Servlets over

traditional CGI Powerful

Servlets support several capabilities that are difficult orimpossible to accomplish with regular CGI- servlets can

directly communicate to web server, whereas regular CGIprograms cannot.

Communicating with the web server makes it easier totranslate relative URLs into concrete path names, for instancemultiple servlets can also share data making it easy to

implement database connection pooling and similarresource-sharing optimization,

Servlets can also maintain information from request torequest, simplifying techniques like session tracking andcaching of previous computation.

Page 16: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 16/24

Advantages of Servlets over

traditional CGI Portable

Servlets are written in java programming language andfollow a standard API (Application Programming

Interface) Servlet written for one server can be run virtually 

unchanges on Apache, Microsoft Internet Informationserver (IIS) IBM webSphere, or StarNine WebStar.

Servlets are supported directly or by plug-in on virtually every major Web server.

They are now part of Java 2 platform, Enterprise Edition(J2EE see http://java.sun.com/j2ee/) so industry supportfor servlets is becoming more pervasive.

Page 17: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 17/24

Advantages of Servlets over

traditional CGI Secure

One of the main source of vulnerability in traditional CGI programsstems from the fact that they are often executed by general-purposeoperating systems shells- so CGI programmer has to be careful to

filter out characters such as backqoutes and semicolons that aretreated specially by the shell.

Second source of problem is the fact that some CGI programs areprocessed by languages that do not automatically checks arrays orstrings bounds. This creates some time buffer overflow problems.

Servlets suffer from neither of these problems Servlets do not use shell for execution of remote systems calls to

invoke a program on the local operating systems

 Array bound checking and other memory protection features are acentral part of the Java programming languages.

Page 18: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 18/24

Advantages of Servlets over

traditional CGI Inexpensive

There are a number of free and very inexpensive webservers available that are good for personal use or low-

 volume websites. Nevertheless, once you have a webserver, no matter its cost, adding Servlets support to itcost very little extra.

This is in contrast to many of the other CGI alternatives,

 which require a significant initial investment topurchase a package.

Page 19: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 19/24

Java Server Pages (JSP)  JSP technology enables you to mix regular static HTML with

dynamically generated content from Servlets. Many Web pages that are built by CGI programs are primarily 

static. For example, initial page at most on-line stores is the same for

all visitors, expect for a small welcome message giving the visitor’s name if it is known. 

Most CGI variations including servlets, make you generate theentire page via your program even through most of it is always

the same.  JSP lets you create the two parts separately, for example most of the pages consists of regular HTML, which is passed to the userunchanged, part that are generated dynamically are marked withspecial HTML-like tag and mixed right into the page. (See thelisting)

Page 20: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 20/24

Java Server Pages (JSP)

 JSP Code

Page 21: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 21/24

Advantages Java Server Pages (JSP) JSP has number of advantages over many of its

alternatives

 JSP verses Active Server Pages (ASP)

 ASP is competing technology from Microsoft

First advantage of JSP is that its dynamic part is writtenin Java, not in VBScript or another ASP specificlanguage, so its is more powerful in situations wherereusability of the code is required.

 JSP is portable to other operating systems and wenservers- not limited to WindowsNT/2000 and IIS.

Page 22: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 22/24

Advantages Java Server Pages (JSP) JSP verses PHP

PHP is a free open source HTML-embedded scriptinglanguage that is some what similar to both JSP and ASP.

The advantage of JSP is that the dynamic part is writtenin Java, which you probably already know, which already has an extensive API for networking database access,distributed objects and the like, whereas PHP requires

learning of entirely new language.

Page 23: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 23/24

Advantages Java Server Pages (JSP)Home reading assignment

Q#1: Compare JSP verses pure Servlets , SSI, JavaScriptand static HTML.

Page 24: WEB Week-1.B Introduction to Web Programing

7/28/2019 WEB Week-1.B Introduction to Web Programing

http://slidepdf.com/reader/full/web-week-1b-introduction-to-web-programing 24/24

End of chapters