Server Technology PPNT Manuale Utente

Navigare online o scaricare Manuale Utente per Software di database Server Technology PPNT. Server-side Technologies CGI, PHP, Java Servlets, JSP Manuale Utente

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 95
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 0
Server-side Technologies
CGI, PHP, Java Servlets, JSP
Denis Helic
Vedere la pagina 0
1 2 3 4 5 6 ... 94 95

Sommario

Pagina 1 - CGI, PHP, Java Servlets, JSP

Server-side TechnologiesCGI, PHP, Java Servlets, JSPDenis Helic

Pagina 2

CGI Specification(3/4)HTTP method used by the client: GET or POSTGET method: external program reads environment variablesQUERY_STRING special environme

Pagina 3

CGI Specification(4/4)CGI specification allows external programs to be written in any program-ming languageUNIX shell scripts, Perl scripts, C programs,

Pagina 4

CGI Examples(1/7)Example 1:Hello World: CGI as UNIX shell scriptGET method, no parameters from clientWrite HTML to st dout#!/bin/sh# send http-header

Pagina 5

CGI Examples(2/7)Example 1 (continued):# send html content:echo "<HTML>"echo " <HEAD>"echo " <TITLE>Hello W

Pagina 6

CGI Examples(3/7)Example 2:Dump environment variables: CGI as Perl scriptGET method, no parameters from clientWrite HTML to st dout#!/usr/bin/perlrequ

Pagina 7

CGI Examples(4/7)Example 2 (continued):Example:http://coronet.iicm.edu:8080/cgi-bin/mmis/p rint env. plSpecial CGI library in Perl: cgi-libProvides fu

Pagina 8

CGI Examples(5/7)Example 3:Dump QUERY_STRING: CGI as Perl scriptGET method, with parameters from clientWrite HTML to st doutParameters encoded in Url:

Pagina 9

CGI Examples(6/7)Example 4:Evaluate HTML forms: CGI as Perl scriptPOST method, with parameters from client, read from stdinWrite HTML to st dout#!/usr

Pagina 10

CGI Examples(7/7)Example 4 (continued):Example:http://coronet.iicm.edu:8080/mmis/examples /cgi /for m.ht ml<form action ="/cgi-bin/mmis/handle

Pagina 11 - CGI Specification(4/4)

CGI Applications(1/2)Long list of different applications:Simple: Hit counters, current date, etc .Handling HTML forms, search engines, imagemaps, datab

Pagina 12 - Write HTML to st dout

Server-side Technologies: Historical Background(1/3)Server-side = Web server sideAt the beginning the Web was a static information systemWeb servers s

Pagina 13 - Example:

CGI Applications(2/2)Finger gateway:http://coronet.iicm.edu:8080/cgi-bin/mmis/f inge r.plSource:http://coronet.iicm.edu:8080/mmis/examples /cgi /finge

Pagina 14 - Example 2:

CGI SecurityCheck parameters carefully!!!if($email =~ /[^a-zA-Z0-9_\-\.@]/){$_ = "The email address should be ofthe form <i>user\@server<

Pagina 15

CGI - PerlLarry Wall: Practical Extraction and Reporting LanguageString manipulations, r egular expressionsVery powerfulStrange syntax :-) (e .g. 1 wh

Pagina 16

PHP: Hypertext Preprocessorhttp://www.php.net(NOT http://www.php .com = Parents helping Parents :-))General purpose scripting language, especially sui

Pagina 17 - Example 4:

PHP: Hello World(1/3)Embed PHP script into an HTML fileUpload the file onto a Web server using extension .phpEmbedding PHP in HTML:< ? ... ? ><

Pagina 18 - Another CGI example:

PHP: Hello World(2/3)Example:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd&quo

Pagina 19 - WWW gateways!

PHP: Hello World(3/3)Example:http://coronet.iicm.edu:8080/mmis/examples /php /hel lo/hello.phpSource:http://coronet.iicm.edu:8080/mmis/examples /php /

Pagina 20 - Mail gateway:

PHP: SyntaxPHP syntax close to C and JavaObject-oriented approachControl structuresWeakly-typed variables (prefix ’$’)Operators, etc.(27/95)

Pagina 21

PHP: ApplicationsWide range of applications (similar to CGI)Forms handling, etc.Wide range of PHP librariesNetwork connectivity (e.g. access FTP, IMAP

Pagina 22 - 1 while s/[(][^()]*[)] //;)

PHP: Handling Forms(1/8)PHP interpreter initializes variables correpsonding to form fi elds<form action ="/mmis/examples/php/env_vars/printvar.

Pagina 23

Server-side Technologies: Historical Background(2/3)There was a need for more interaction between users and the system (e.g.phone books)HTML formsServ

Pagina 24 - <% ... %>

PHP: Handling Forms(2/8)PHP form variables: Alternative 1PHP variables have same names as form fields$name for name, $nr for nr, etc.<?phpecho "

Pagina 25 - PHP: Hello World(2/3)

PHP: Handling Forms(3/8)Example with GET:http://coronet.iicm.edu:8080/mmis/examples /php /env _var s/var_get.htmlExample with POST:http://coronet.iicm

Pagina 26 - PHP: Hello World(3/3)

PHP: Handling Forms(4/8)PHP form variables: Alternative 2Access form fields through PHP array$HTTP_POST_VARS for POST method$HTTP_GET_VARS for GET meth

Pagina 27

PHP: Handling Forms(5/8)PHP form variables: Alternative 3Access form fields through PHP array$_POST for POST method (>=PHP4. 1.0)$_GET for GET metho

Pagina 28

PHP: Handling Forms(6/8)Handling forms: Security issuesSimilar problems like with CGIWe need to check parameters sent by users very carefully!!!PHP fo

Pagina 29 - PHP: Handling Forms(1/8)

PHP: Handling Forms(7/8)Example of security problem with global form variables$tempfile = "1 2345 .tmp ";... han dle form variables ... d

Pagina 30 - PHP: Handling Forms(2/8)

PHP: Handling Forms(8/8)Example of security problem with global form variables (continued)Suppose a following HTML form:<input type = "hidden&

Pagina 31 - Source PHP:

PHP: Database Manipulation(1/5)Huge advant age of PHP: great s upport for database connectivityAdabas-D, mSQL, MySQL, Oracle, Postgres, Slid, Sybase/S

Pagina 32 - PHP: Handling Forms(4/8)

PHP: Database Manipulation(2/5)Example: Inserting and retrieving data from MySQL databaseForm:http://coronet.iicm.edu:8080/mmis/examples /php /mys ql/

Pagina 33 - PHP: Handling Forms(5/8)

PHP: Database Manipulation(3/5)<?php$name = $HTTP_ POST _VAR S["n ame" ];$second_name = $HTTP_POST_VARS["second_name"];$nr = $H

Pagina 34

Server-side Technologies: Historical Background(3/3)Need to extend the functionality of Web serversDon’t add the new functionality into Web servers di

Pagina 35 - PHP: Handling Forms(7/8)

PHP: Database Manipulation(4/5)Inserting data with PHP (source):http://coronet.iicm.edu:8080/mmis/examples /php /mys ql/register.phpsRetrieving data w

Pagina 36 - >=PHP4.2.0 by default off

PHP: Database Manipulation(5/5)...while($i < $ro ws){$name = mysql_ resu lt($ resu lt, $i, "name");$second_name = mysql_result($result, $

Pagina 37

PHP: XML Manipulation(1/3)Additional PHP library for manipulating XML dataPEAR library: http://pear.ph p.ne t/Packages for networking, scientific calcu

Pagina 38

PHP: XML Manipulation(2/3)header("Content-Type: text/xml");include("XML/Tree.php");$tree = new X ML_T ree( );$root = & $tree-&

Pagina 39

PHP: XML Manipulation(3/3)Retrieving data (as XML) with PHP:http://coronet.iicm.edu:8080/mmis/examples /php /xml /get _registered.phpRetrieving data (

Pagina 40 - Retrieving data with PHP:

PHP: Image Manipulation(1/3)Generate not only HTML, but digital images as well!PHP compiled with GD graphical libraryStandard installation c omes with

Pagina 41

PHP: Image Manipulation(2/3)Header("Content-Type: image/png");...$im = ImageCre ateT rueC olor (400 , 300);...ImageFill($im, 0, 0, $ whit e)

Pagina 42

PHP: Image Manipulation(3/3)Retrieving data (as PNG image) with PHP:http://coronet.iicm.edu:8080/mmis/examples /php /ima ge/get_stats.phpRetrieving da

Pagina 43 - PHP: XML Manipulation(2/3)

PHP: Tutorials and ResourcesPHP Introductory Tutorial:http://www.php.net/tut.phpPHP/MySQL Tutorial:http://hotwired.lycos.com/webmonkey/progra mmin g/p

Pagina 44 - PHP: XML Manipulation(3/3)

Java Servlets and Java Server Pages (JSP)Intro tutorial:http://www.apl.jhu.edu/~hall/java/Servlet-T utor ial/Book: Marty Hall, Core Servlets and JavaS

Pagina 45 - PHP: Image Manipulation(1/3)

Server-side Technologies: TodayMore than just evaluating of HTML formsDynamic content neede d for:Sophisticated user interaction (e.g. search engines,

Pagina 46 - PHP: Image Manipulation(2/3)

Java ServletsJava technology’s answer to CGI programmingJava programs that run on a Web serverJava servlet engine (container)Official Reference Implemen

Pagina 47 - PHP: Image Manipulation(3/3)

Java Servlets: Advantages(1/4)EfficientWith traditional CGI: for e ach request a new OS process is startedJava VM, servlet container, and a particular s

Pagina 48

Java Servlets: Advantages(2/4)ConvinientIf you already know Java (most probabaly you do ;))Huge Java software librariesLibraries for handling cookies,

Pagina 49

Java Servlets: Advantages(3/4)PowerfulJava servlets can talk directly to the Web se rver (e .g. lookup forimages stored in standard places)Servlets ca

Pagina 50

Java Servlets: Advantages(4/4)PortableWritten in Java with a standardized APIServlets written for Microsoft IIS will run on Apache and other Webserver

Pagina 51

Installing Servlet Container(1/3)Servlet ContainerTomcathttp://jakarta.apache.org/tomcat/index.htm lApache software foundationhttp://www.apache.orgfor

Pagina 52 - Huge Java software libraries

Installing Servlet Container(2/3)installation tomcat# installation in verzeichnis ’/foo ’cd /foounzip <path-to-tomcat-archive>/jakarta-tomcat-4

Pagina 53

Installing Servlet Container(3/3)Windows installation with Windows installerInstalled as a Windows serviceConnecting with a Web server (e.g. Apache)In

Pagina 54

Java Servlets - Internal(1/2)Java class extending abstract classjavax.servlet.http.HttpServletImplement public void doGet(request, respons e) to handl

Pagina 55 - Apache software foundation

Java Servlets - Internal(2/2)servlet template:import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class SomeServlet extends Ht

Pagina 56

Communication between Web server and external programsHow should Web server communicate with external programs?Passing parameters, getting response, e

Pagina 57

Java Servlets: Hello World(1/5)Example: Hello World!...public void doGet(HttpServletRequest re ques t, HttpServletResponse response)throws ServletExce

Pagina 58

Java Servlets: Hello World(2/5)Installing and running the HelloWorldServletTomcat web applications (in webapp directory)|-mmis-servlets| || |-WEB-INF|

Pagina 59 - Java Servlets - Internal(2/2)

Java Servlets: Hello World(3/5)web.xml declares all servlets in a particular Web application<?xml version="1.0" encoding="ISO-8859-1

Pagina 60 - Example: Hello World!

Java Servlets: Hello World(4/5)Hello World:http://coronet.iicm.edu/mmis-servlets/Hello Worl dSource code:http://coronet.iicm.edu/mmis/examples/java /h

Pagina 61

Java Servlets: Hello World(5/5)Element Construction Set (Apache project)http://jakarta.apache.org/ecs/Supports generation of HTML and XMLNo need for n

Pagina 62

Java Servlets: HTTP and Environment Variables(1/2)Similar communication mechanism between a Java servlet and the WebserverAll communication wrapped in

Pagina 63 - Source code:

Java Servlets: HTTP and Environment Variables(2/2)CGI Variables:http://coronet.iicm.edu/mmis-servlets/CGIVa rSource code:http://coronet.iicm.edu/mmis/

Pagina 64 - ECSHelloWorldServlet.java

Java Servlets: Handling Forms(1/2)All form parsing done automaticallyInvoke a method on the instance of HttpServletRequest class to obtainparametersSt

Pagina 65

Java Servlets: Handling Forms(2/2)Example with GET:http://coronet.iicm.edu/mmis/examples/java /for m/fo rm_get.htmlExample with POST:http://coronet.ii

Pagina 66 - HTTP Headers:

Java Servlets: Database Manipulation(1/5)Advantage of Java: great support for database connectivitySimilar to PHPJava Database Connectivity - JDBChttp

Pagina 67

Common Gateway Interface (CGI)CGI is a specification of communication between Web server and externalprogramsCurrent version CGI 1.1http://hoohoo.ncsa.

Pagina 68

Java Servlets: Database Manipulation(2/5)Example: Inserting and retrieving data from MySQL databaseForm for inserting data:http://coronet.iicm.edu/mmi

Pagina 69

Java Servlets: Database Manipulation(3/5)Connection connection = DriverManager.getConnection("jdbc:mysql://" + dbms_host_ + "/" +

Pagina 70 - Form for inserting data:

Java Servlets: Database Manipulation(4/5)Retrieving data with JavaConnection connection = DriverManager.getConnection(...);Statement statement = conne

Pagina 71

Java Servlets: Database Manipulation(5/5)Retrieving data with Javahttp://coronet.iicm.edu/mmis-servlets/Regis trat ionRetrieving data with Java (sourc

Pagina 72 - Retrieving data with Java

Java Servlets: XML Manipulation(1/2)Java SE 1.4+ includes library for manipulating XML dataElement root = documen t.cr eate Elem ent( "Cou rse&qu

Pagina 73

Java Servlets: XML Manipulation(2/2)Retrieving data (as XML) with Java:http://coronet.iicm.edu/mmis-servlets/XMLRe gist rati onRetrieving data (as XML

Pagina 74

Java Servlets: Tutorials and ResourcesJava Servlets Introductory Tutorial:http://www.apl.jhu.edu/~hall/java/Servlet-T utor ial/Book: Marty Hall, Core

Pagina 75 - XMLRegistrationServlet.java

Java Server Pages (JSP)Combine static HTML with Java Code<HTML><HEAD><TITLE>JSP-Hello World</TITLE></HEAD><BODY>St

Pagina 76

Java Server Pages (JSP) - InternalJSP pages are converted to Java classes<tomcat-dir>/work/localhost/helloworld$jsp .jav aclassname:helloworld$j

Pagina 77 - HelloWorld JSP:

JSP Elements(1/7)JSP expression<%= "H ello World <BR>" %>XML syntax: <jsp:expression>"HelloWorld<BR>"</

Pagina 78

CGI Specification(1/4)Environment variablesSystem specific variables set by Web serverExternal program reads environment variables and obtains dataabout

Pagina 79 - </jsp:expression>

JSP Elements(2/7)JSP Scriplet<% out .pri nt(" Hell o World <BR>"); %>XML syntax: <jsp:scriptlet>out.print("HelloWorld

Pagina 80

JSP Elements(3/7)JSP Declaration<%! pr ivat e int access_count = 0; %>XML syntax: <jsp:declaration>privateintaccess_count=0</jsp:declar

Pagina 81 - </jsp:declaration>

JSP Elements(4/7)JSP Page Directive<%@ pa ge import = "java.util.*" %>XML syntax: <jsp:directive.page import=”java.util.∗”/>Dire

Pagina 82 - JSP Page Directive

JSP Elements(5/7)JSP commentsJSP Include Directive (includes other files at run-time)JSP Elements to handle Java Beans(83/95)

Pagina 83 - JSP comments

JSP Elements(6/7)JSP predefined variablesrequest, responseoutsessionconfig, pageContext(84/95)

Pagina 84

JSP Elements(7/7)Example:http://coronet.iicm.edu/mmis-servlets/jsp/e xamp le.j spExample:http://coronet.iicm.edu/mmis-servlets/jsp/e xamp le.j sp?data

Pagina 85 - JSP Elements(7/7)

Servlets, CGI, JSP, PHP, ... - Problems!(1/3)Common problems of all server-side generated Web applicationsMixing of content and presentationHard to de

Pagina 86

Servlets, CGI, JSP, PHP, ... - Problems!(2/3)Servlets have this problem alsoPresentation designer needs to program in JavaPossible solutionDump conten

Pagina 87 - Possible solution

Servlets, CGI, JSP, PHP, ... - Problems!(3/3)Java Web Frameworks try to solve this problemCoocon (XML Publishing framework)http://xml.apache.org/cocoo

Pagina 88

Servlets, CGI, JSP, PHP, ... - What to take?Depends on application requirements (e.g. database connectivity, perfor-mance, etc.)Depends on know-how, t

Pagina 89

CGI Specification(2/4)Standard InputUsed by the server to send client data to external programStandard OutputUsed by external program to send response

Pagina 90 - Session Tracking(1/5)

Session Tracking(1/5)HTTP is connection-less: one connection per requestInformation about user/session is lost whenever the connection is closedOften

Pagina 91

Session Tracking(2/5)Keep track with:CookiesHidden form fields:<INPUT type=”HIDDEN”name=”sessionInfo”value=”username”>Url-rewriting:e.g. http://c

Pagina 92 - Session Tracking(3/5)

Session Tracking(3/5)CookiesStrings sent from server to Web browserStored on a client side database, files or in memorySent back from browser to the We

Pagina 93 - Session Tracking(4/5)

Session Tracking(4/5)Used to store the state of communication between a client and the serverServer sets the read rigths for a cookie (i.e. who can re

Pagina 94 - SessionServlet.java

Session Tracking(5/5)High level interfaces in PHP, Java Servlets APIJava servlets API manages sessions with cookies or url rewritingTransparent to pro

Pagina 95 - Web services

Distributed Programming on the WebVery hot topic right now.NET from MicrosoftWeb servicesMore on Web ser vices in MMIS 2(95/95)

Commenti su questo manuale

Nessun commento