10. Java Servelet. Introduction

Similar documents
People Data and the Web Forms and CGI CGI. Facilitating interactive web applications

CGI An Example. CGI Model (Pieces)

How to write a CGI for the Apache Web server in C

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

HTTP Protocol. Bartosz Walter

Description of Microsoft Internet Information Services (IIS) 5.0 and

Network Technologies

Chapter 27 Hypertext Transfer Protocol

Forms, CGI Objectives. HTML forms. Form example. Form example...

People Data and the Web Forms and CGI. HTML forms. A user interface to CGI applications

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

INTRUSION DETECTION AND PREVENTION SYSTEM: CGI ATTACKS. A Thesis. Presented to. The Faculty of the Department of Computer Science

Working With Virtual Hosts on Pramati Server

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

CGI Programming on the World Wide Web

By Bardia, Patit, and Rozheh

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

APACHE WEB SERVER. Andri Mirzal, PhD N

Oracle9i Application Server: Options for Running Active Server Pages. An Oracle White Paper July 2001

Web Application Development

1 Introduction: Network Applications

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

ICANWK414A Create a common gateway interface script

HTTP. Internet Engineering. Fall Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Lecture 2. Internet: who talks with whom?

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

NAT TCP SIP ALG Support

7 Why Use Perl for CGI?

Guide to Analyzing Feedback from Web Trends

Lecture 11 Web Application Security (part 1)

reference: HTTP: The Definitive Guide by David Gourley and Brian Totty (O Reilly, 2002)

SOA Software API Gateway Appliance 7.1.x Administration Guide

WebObjects Deployment Guide Using JavaMonitor. (Legacy)

WEB DATABASE PUBLISHING

Enabling Single Signon with IBM Cognos ReportNet and SAP Enterprise Portal

WEB SERVICES. Revised 9/29/2015

OVERVIEW OF ASP. What is ASP. Why ASP

A Java proxy for MS SQL Server Reporting Services

What Is the Java TM 2 Platform, Enterprise Edition?

Web Hosting Features. Small Office Premium. Small Office. Basic Premium. Enterprise. Basic. General

CS640: Introduction to Computer Networks. Applications FTP: The File Transfer Protocol

A Tool for Evaluation and Optimization of Web Application Performance

Talk Internet User Guides Controlgate Administrative User Guide

Client/server is a network architecture that divides functions into client and server

Interfacing the Apache Web Server to APLX

Web Services April 21st, 2009 with Hunter Pitelka

SIP: Protocol Overview

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

About This Document 3. Integration and Automation Capabilities 4. Command-Line Interface (CLI) 8. API RPC Protocol 9.

TED 5000 Third Party Posting API

Manual. Netumo NETUMO HELP MANUAL Copyright Netumo 2014 All Rights Reserved

Web Server Manual. Mike Burns Greg Pettyjohn Jay McCarthy November 20, 2006

Computer Networks 1 (Mạng Máy Tính 1) Lectured by: Dr. Phạm Trần Vũ MEng. Nguyễn CaoĐạt

If your organization is not already

LabVIEW Internet Toolkit User Guide

USING CGI WITH LABVIEW

11.1 Web Server Operation

Easy CramBible Lab DEMO ONLY VERSION Test284,IBM WbS.DataPower SOA Appliances, Firmware V3.6.0

Enabling Kerberos SSO in IBM Cognos Express on Windows Server 2008

Building Java Servlets with Oracle JDeveloper

HP Education Services

Web Server for Embedded Systems

Nuance Mobile Developer Program. HTTP Services for Nuance Mobile Developer Program Clients

Basic Internet programming Formalities. Hands-on tools for internet programming

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

INT322. By the end of this week you will: (1)understand the interaction between a browser, web server, web script, interpreter, and database server.

Appendix. Web Command Error Codes. Web Command Error Codes

Implementation of Embedded Web server using TEA algorithm

The HTTP Plug-in. Table of contents

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

EVALUATION OF SERVER-SIDE TECHNOLOGY FOR WEB DEPLOYMENT

CONTENT of this CHAPTER

Design Notes for an Efficient Password-Authenticated Key Exchange Implementation Using Human-Memorable Passwords

at () in C:\wamp\www\icaatom-1.2.0\icaatom \plugins\sfLucenePlugin\lib\vendor\Zend\Search\Lucene\Document.php line

Instructor: Betty O Neil

The Web: some jargon. User agent for Web is called a browser: Web page: Most Web pages consist of: Server for Web is called Web server:

URLs and HTTP. ICW Lecture 10 Tom Chothia

Exploiting the Web with Tivoli Storage Manager

Introduction to Computer Security

Spectrum Technology Platform

World Wide Web. Before WWW

Abstract. 1. Introduction

8/9/16. Server-Side Web Programming Intro. The Hamburger Model. To make a Web server based program

THE PROXY SERVER 1 1 PURPOSE 3 2 USAGE EXAMPLES 4 3 STARTING THE PROXY SERVER 5 4 READING THE LOG 6

Enabling Single Signon with IBM Cognos 8 BI MR1 and SAP Enterprise Portal

Greenstone Documentation

Oracle Exam 1z0-102 Oracle Weblogic Server 11g: System Administration I Version: 9.0 [ Total Questions: 111 ]

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

INTRODUCTION TO WEB TECHNOLOGY

DEPLOYMENT GUIDE Version 2.1. Deploying F5 with Microsoft SharePoint 2010

UNIVERSAL WEB APPLICATION SERVER MAYUMBO NYIRENDA. Department of Computer Science

Dispatcher. PDF Generated : :40:15.

T320 E-business technologies: foundations and practice

Using TestLogServer for Web Security Troubleshooting

Transcription:

Chapter 10 Java Servlets 227 10. Java Servelet Introduction Java TM Servlet provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlets are the Java platform technology of choice for extending and enhancing Web servers. Servlets provide a component-based, platformindependent method for building Web-based applications, without the performance limitations of CGI programs. Servlets have access to the entire family of Java APIs, including the JDBC API to access enterprise databases. Servlets can also access a library of HTTP-specific calls and receive all the benefits of the mature Java language, including portability, performance, reusability, and crash protection. Servlets are a popular choice for building interactive Web applications. Third-party servlet containers are available for Apache Web Server, iplanet Web Server, Microsoft IIS, and others. Servlet containers can also be integrated with Web-enabled application servers, such as BEA WebLogic Application Server, IBM WebSphere, iplanet Application Server, etc. Java Server Page (JSP) technology is an extension of the servlet technology created to support authoring of HTML and XML pages. It makes it easier to combine fixed or static template data with dynamic content. Even if you're comfortable writing servlets, there are several compelling reasons to investigate JSP technology as a complement to your existing work.

Chapter 10 Java Servlets 228 Client Computer/Web Browser HTTP Internet HTML Files HTTP HTTP Server CGI Program Server Computer Figure 1. CGI and HTTP Server Types of Servlets: Internal Servlets Admin Servlet CGI Servlet File Servlet Imagemap Servlet Invoker Servlet: invoke user Servlet Server-Side Include Servlet

Chapter 10 Java Servlets 229 Web Service Request HTTP Web Server Computer Web Browser Response Servlets JDBC SQL Database Java Web Server Using Servlets Basic Flow within the Servlet 1. Load Servlet 2. Initialize the Servlet: init() 3. HTML POST request: depost() 4. The Servlet perform some processing and return the response via an output stream Writing Servlets 1. Create a new Servlet class that extends javax.servlet.http.httpservlet to give javax.servlet.http.httpservletrreuest class 2. Override one or both doget() and dopost() methods How Does Servlet benefits Over CGI? As we know CGI program is not secure enough to send credit card information. Servlets are effective for developing Web-based solutions that help provide secure access to a Web site, that interact with database on

Chapter 10 Java Servlets 230 behalf of a client and maintain unique session information for each client. How does HTML page interact with Servlets? The request-response model of communication is the foundation for Java servlets. Request-response model: when client requests that some action be performed and the server performs the action and responds to the client. The servlets communicate between clients and the servers via the HTTP protocol of the World Wide Web. A client sends an HTTP request to the server. The server receives the request and directs it to be processed by appropriate servlets. The servlets do their processing (which often includes interacting with a database). Then return their results to the --in the form of HTML documents to display in a browser. How Does HTML page connect to Servlet? By using GET and POST Methods, the two most common HTTP request methods that can send data to the server. Get Request Method The primary purpose of an HTTP Get request is to retrieve the content of a specified URL normally the content is an HTML document (e.g. a Web page or an image). Post Request Method Often used to post data from an HTML form to a server-side form handler that processes the data.

Chapter 10 Java Servlets 231 On the data base query applications, the servlet stores the result of the update form (may be student base: student name and the social security number in a file on the server). When user responds to the update form, the servlet HTTPPostServlet sends an HTML document to the client summarizing the results of the form to this point. When user enters the information (student name and the social security number) and presses Submit, the browser sends an HTTP POST request to the servlet. The servlet reading the previous update results from a file on the server Updating the results, Writing the update results back to the file on the server and sending a Web page to the client indicating the cumulative results of the update form. Common Gateway Interface The Common Gateway Interface (CGI) is a standard for interfacing Web applications with information servers such as HTTP or Web servers in a platformindependent manner. Some common Web-based client/server tasks that performed by CGI scripts (programs) include Query database Perform calculations Solicit and interpret user-supplied data Retrieve requested information Produced customized content A CGI program is an executable program that resided in a special directory such as /cgi-bin. It can be written in any language: C/C++, Fortran, Perl, TCL, any UNIX shell, Visual Basic, and AppleScript. The CGI has been in use by the World-Wide Web since 1993. The CGI specification can be found at the following Web sites:

Chapter 10 Java Servlets 232 CGI/1.1 Draft Specification ftp://ftp.ietf.org/internet-drafts/draft-coar-cgi-v11-0x.txt The CGI RFC Project Home Page www.golux.com/coar/cgi/ The Unofficial FastCGI Home Page www.fastcgi.com mod_perl: The Apache/Perl Integration Project perl.apache.org Apache:Session www.perl.com/cpan/modules/by-module/apache/ Velocigen (Binary Evolution) www.velocigen.com Features of CGI Scripting Dynamic Web applications Small programs that communicate with Web servers, which reply the requests from Web browsers Add additional capabilities to the HTTP server Work as a gateway to handle complex tasks for the HTTP server Generate documents on the fly that are capable of incorporating information which changes or which cannot be determined in advance CGI scripts are distinguished from HTML files through o The most common extension for scripts is a suffix of.cgi with the scripts being placed in a separate directory (/cgi-bin) o Windows servers use the extension.exe or.pl Only a HTTP server can interact with a script. A client program cannot directly run a CGI script. It will likely to display the script's source code HTTP Transaction of a Web Browser/Server 1. Web client specify an URL for obtaining a file (for example: www.microsoft.com/docs/index.html)

Chapter 10 Java Servlets 233 2. The Web browser interprets the URL and sends a "GET" request of the HTTP protocol to the server located at www.microsoft.com, asks for the desired file docs/index.html. 3. The server receives and parse the request using CGI protocol 4. The servers then sends the file, with a header to indicate the content type as "Content -type: text/html", back to the browser 5. The "Content -type: text/html" header tells the browser that the data is HTML, so the browser formats and renders the text appropriately CGI Environment Variables and HttpServletRequest Methods AUTH_TYPE getauthtype() If the server supports user authentication, and the script is protects, this is the protocol-specific authentication method used to validate the user. CONTENT_TYPE getcontenttype() It specifies the media type of the data for queries, which have attached information, such as HTTP POST and PUT, this is the content type of the data. CONTENT_LENGTH getcontentlength() The length (number of bytes) of information passed to the script. GATEWAY_INTERFACE The name and version of the protocol being used by the server to communicate with the script. Format: CGI/revision HTTP_ACCEPT Gives a comma-separated list of MIME types that the client can accept. HTTP_REFERER Provides the URL address of the page where the request originated. HTTP_USER_AGENT Specifies the name of the client program and version used to make the request. PATH_INFO getpathinfo() It provides any extra path information, as given in the URL, for accessing this script. The extra information is sent as PATH_INFO to be decoded by the server before it is passed to the CGI script. PATH_TRANSLATED getpathtranslated() It gives the absolute filesystem path for access the script. The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it.

Chapter 10 Java Servlets 234 QUERY_STRING getquerystring() Any additional information passed to the script after the? mark in the URL which referenced this script is called the query information. It should not be decoded in any fashion. REMOTE_HOST getremotehost() It contains a fully qualified domain name of the client computer. If the host name cannot be determined, it should set REMOTE_ADDR to hold the IP address of the host and leave this variable unset. REMOTE_ADDR getremoteaddr() The IP address of the remote client computer making the request. REMOTE_IDENT The client machine's username. Usage of this variable should be limited to logging only. SCRIPT_NAME getservletname() A virtual path to the script being executed, used for self-referencing URLs. REMOTE_USER getremoteuser() The name used to authenticate the user for accessing the script. SERVER_SOFTWARE The name and version of the information server software answering the request (and running the gateway). # Format: name/version SERVER_NAME getservername() The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs. SERVER_PROTOCOL getprotocol() The name and revision of the information protocol this request came in with. Format: protocol/revision SERVER_PORT getserverport() The port number to which the request was sent. REQUEST_METHOD getmethod() The method with which the request was made. For HTTP, this is "GET", "HEAD", "POST", etc. HTTP Status Codes HTTP Working Group: http://www.w3.org/protocols/http RFC 2616(HTTP 1.1):http://www.cis.ohio-state.edu/htbin/rfc/rfc2616.html 100 Continue 101 Switching Protocols 199 Misc.

Chapter 10 Java Servlets 235 Successful Codes 200 OK, the request was fulfilled 201 Created, following a POST command, indicates the URI by which the newly created document should be known 202 Accepted, the request has been accepted for processing, but the processing has not been completed 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 299 Miscellaneous information Redirection Codes 300 Multiple Choices, multiple documents available 301 Moved Permanently 302 Moved temporarily 303 See other document 304 Not modified since last retrieval 305 Use Proxy 306 Switch proxy 307 Document moved temporarily 399 Misc. Client Errors Code 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Request Entity Too Large 414 Request-URI Too Long 415 Unsupported Media Type 416 Requested range not valid 417 Failed 418 Failed Server Error 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported 506 Redirection failed