660 likes | 803 Vues
Lecture 3 Web Technologies Part 2. Web Technologies. HTML XHTML CSS XML JavaScript VBSCRIPT DOM DHTML AJAX E4X WMLScript SQL. ASP ADO PHP CGI PERL .NET SMIL SVG FLASH Java applets Java servlets Java Server page. What is SQL?.
E N D
Web Technologies • HTML • XHTML • CSS • XML • JavaScript • VBSCRIPT DOM • DHTML • AJAX • E4X • WMLScript • SQL • ASP • ADO • PHP • CGI • PERL • .NET • SMIL • SVG • FLASH • Java applets • Java servlets • Java Server page
What is SQL? • SQL stands for Structured Query Language • SQL allows you to access a database • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert new records in a database • SQL can delete records from a database • SQL can update records in a database • SQL is easy to learn
SQL Data Manipulation Language (DML) • SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records. • These query and update commands together form the Data Manipulation Language (DML) part of SQL: • SELECT - extracts data from a database table • UPDATE - updates data in a database table • DELETE - deletes data from a database table • INSERT INTO - inserts new data into a database table
SQL Data Definition Language (DDL) • The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables. • The most important DDL statements in SQL are: • CREATE TABLE - creates a new database table • ALTER TABLE - alters (changes) a database table • DROP TABLE - deletes a database table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index
SQL on the WEB • Many web applications require database at the back side. • We can use SQL for database activities. • We use SQL together with other technologies.
SQL Example with ASP <html> <head> <title>My First ASP Page</title> </head> <body bgcolor="white" text="black"> <% Dim adoCon Dim rsGuestbook Dim strSQL 'Create an ADO connection object Set adoCon = Server.CreateObject("ADODB.Connection") 'Set an active connection to the Connection object using a DSN-less connection adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("mydb.mdb") 'Create an ADO recordset object Set rsGuestbook = Server.CreateObject("ADODB.Recordset") 'Initialise the strSQL variable with an SQL statement to query the database strSQL = "SELECT Friends.Name, Friends.link FROM Friends;" 'Open the recordset with the SQL query rsGuestbook.Open strSQL, adoCon
SQL Example with ASP 'Loop through the recordset Do While not rsGuestbook.EOF 'Write the HTML to display the current record in the recordset Response.Write ("<br>") Response.Write (rsGuestbook("Name")) Response.Write ("<br>") Response.Write (rsGuestbook("link")) Response.Write ("<br>") Response.Write("Murat Koyuncu") 'Move to the next record in the recordset rsGuestbook.MoveNext Loop 'Reset server objects rsGuestbook.Close Set rsGuestbook = Nothing Set adoCon = Nothing %> </body> </html>
What is ASP? • ASP stands for Active Server Pages. • ASP is a program that runs inside IIS. • IIS stands for Internet Information Services. • IIS comes as a free component with Windows Servers. • PWS is a smaller - but fully functional - version of IIS (for Windows 95/98).
ASP Compatibility • ASP is a Microsoft Technology. • To run IIS you must have Windows NT 4.0 or later. • To run PWS you must have Windows 95 or later.
What is an ASP File? • An ASP file is just the same as an HTML file. • An ASP file can contain text, HTML, XML, and scripts. • Scripts in an ASP file are executed on the server. • An ASP file has the file extension ".asp“.
How Does ASP Differ from HTML? • When a browser requests an HTML file, the server returns the file. • When a browser requests an ASP file, IIS passes the request to the ASP engine. • The ASP engine reads the ASP file, line by line, and executes the scripts in the file. • Finally, the ASP file is returned to the browser as plain HTML.
What can ASP do for you? • Dynamically edit, change or add any content of a Web page. • Respond to user queries or data submitted from HTML forms. • Access any data or databases and return the results to a browser. • Customize a Web page to make it more useful for individual users. • The advantages of using ASP instead of CGI and Perl, are those of simplicity and speed. • Provide security since your ASP code can not be viewed from the browser. • Clever ASP programming can minimize the network traffic. Important: Because the scripts are executed on the server, the browser that displays the ASP file does not need to support scripting at all!
ASP Example <html> <body><%response.write("Hello World!")%> </body> </html>
ASP Example-Code <html> <body><%response.write(FormatDateTime(date(),vbgeneraldate))response.write("<br />")response.write(FormatDateTime(date(),vblongdate))response.write("<br />")response.write(FormatDateTime(date(),vbshortdate))response.write("<br />")response.write(FormatDateTime(now(),vblongtime))response.write("<br />")response.write(FormatDateTime(now(),vbshorttime))%><p>Syntax for FormatDateTime:FormatDateTime(date,namedformat).</p></body></html>
ASP Example-Output 12/10/2007 Monday, December 10, 2007 12/10/2007 9:16:58 AM 09:16 Syntax for FormatDateTime: FormatDateTime(date,namedformat).
What is ADO? • ADO is a Microsoft technology. • ADO stands for ActiveX Data Objects. • ADO is a Microsoft Active-X component. • ADO is automatically installed with Microsoft IIS. • ADO is a programming interface to access data in a database.
Accessing a Database from an ASP Page The common way to access a database from inside an ASP page is to: • Create an ADO connection to a database. • Open the database connection. • Create an ADO recordset. • Open the recordset. • Extract the data you need from the recordset. • Close the recordset. • Close the connection.
Create a Database Connection <% setconn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" %>
An ODBC Connection to an MS Access Database Here is how to create a connection to a MS Access Database: • Open the ODBC icon in your Control Panel. • Choose the System DSN tab. • Click on Add in the System DSN tab. • Select the Microsoft Access Driver. Click Finish. • In the next screen, click Select to locate the database. • Give the database a Data Source Name (DSN). • Click OK.
An ODBC Connection to an MS Access Database <% set conn=Server.CreateObject ("ADODB.Connection") conn.Open "northwind" %> Name defined in ODBC
Create an ADO Table Recordset <% Setconn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb“ Setrs=Server.CreateObject("ADODB.recordset") rs.Open "Customers", conn %>
Create an ADO SQL Recordset <% Set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0“ conn.Open "c:/webdata/northwind.mdb“ set rs=Server.CreateObject("ADODB.recordset") rs.Open "Select * from Customers", conn %>
Extract Data from the Recordset <% ..... for each x in rs.fields response.write(x.name) response.write(" = ") response.write(x.value) next .... %>
ADO Example <html> <body> <% setconn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb“ set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT * FROM Customers", conn do until rs.EOF for each x in rs.Fields Response.Write(x.name) Response.Write(" = ") Response.Write(x.value & "<br />") next Response.Write("<br />") rs.MoveNext loop rs.close conn.close %> </body> </html>
What is PHP? • PHP stands for PHP: Hypertext Preprocessor. • PHP is a server-side scripting language, like ASP. • PHP scripts are executed on the server. • PHP supports many databases (MySQL, Informix, Oracle, Sybase,Solid,PostgreSQL,Generic ODBC, etc.) • PHP is an open source software (OSS). • PHP is free to download and use.
What is a PHP File? • PHP files may contain text, HTML tags and scripts. • PHP files are returned to the browser as plain HTML. • PHP files have a file extension of ".php", ".php3", or ".phtml"
Why PHP? • PHP runs on different platforms (Windows, Linux, Unix, etc.). • PHP is compatible with almost all servers used today (Apache, IIS, etc.). • PHP is FREE to download from the official PHP resource: www.php.net. • PHP is easy to learn and runs efficiently on the server side.
A free web server platform • Install an Apache server on a Windows or Linux machine. • Install PHP on a Windows or Linux machine. • Install MySQL on a Windows or Linux machine.
What do PHP code look like? • PHP is a rather simple language. • Much of its syntax is borrowed from C except for dealing with the types of variables. • You don't need to think of the types of variables at all - you just work with their values, not their types. • And you don't have to declare variables before you use them.
A simple PHP example <html> <body> <?php echo "Hello World"; ?> </body> </html>
PHP Examples <html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?> </body> </html> <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> </body> </html>
PHP Database Example <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } mysql_close($con); ?>
PHP ODBC Connection <html> <body> <?php $conn=odbc_connect('northwind','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM customers"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table><tr>"; echo "<th>Companyname</th>"; echo "<th>Contactname</th></tr>"; while (odbc_fetch_row($rs)) { $compname=odbc_result($rs,"CompanyName"); $conname=odbc_result($rs,"ContactName"); echo "<tr><td>$compname</td>"; echo "<td>$conname</td></tr>"; } odbc_close($conn); echo "</table>"; ?> </body> </html>
What is CGI? • The Common Gateway Interface (CGI) is a standard for interfacing external applications with information servers, such as HTTP or Web servers. • A plain HTML document that the Web daemon retrieves is static, which means it exists in a constant state: a text file that doesn't change. • A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information.
What is CGI? • For example, let's say that you wanted to "hook up" your Unix database to the World Wide Web, to allow people from all over the world to query it. • Basically, you need to create a CGI program that the Web daemon will execute to transmit information to the database engine, and receive the results back again and display them to the client. • This is an example of a gateway, and this is where CGI, currently version 1.1, got its origins.
What is CGI? • A CGI program can be written in any language that allows it to be executed on the system, such as: • C/C++ • Fortran • PERL • TCL • Any Unix shell • Visual Basic • AppleScript
What is MS .NET • .NET is Microsoft's new Internet and Web strategy. • .NET is NOT a new operating system. • .NET is a new Internet and Web based infrastructure. • .NET delivers software as Web Services. • .NET is a framework for universal services. • .NET is a server centric computing model. • .NET will run in any browser on any platform. • .NET is based on the newest Web standards.
.NET Internet Standards • HTTP, the communication protocol between Internet Applications. • XML, the format for exchanging data between Internet Applications. • SOAP, the standard format for requesting Web Services. • UDDI, the standard to search and discover Web Services.
.NET Framework • The .NET Framework is the infrastructure for the new Microsoft .NET Platform. • The .NET Framework contains common class libraries - like ADO.NET, ASP.NET and Windows Forms. • The .NET Framework is language neutral. Currently it supports C++, C#, Visual Basic, JScript (The Microsoft version of JavaScript) and COBOL. • The new Visual Studio.NET is a common development environment for the new .NET Framework.
.NET Building Blocks • Web Services: Web Services provide data and services to other applications (HTTP, HTML, XML, and SOAP). • Internet Directory Services: .NET supports a new kind of directory services that can answer XML based questions about Internet Services, far more exactly than search engines and yellow pages. These services are built on the UDDI standard. • There are also some others…
.NET Software • Windows.NET: Windows 2000 and Windows XP • ASP.NET • Visual Studio.NET • Visual Basic.NET • SQL Server 2000 • Internet Information Services 6.0
XML Based Web Protocols • SOAP: SOAP (Simple Object Access Protocol) is a lightweight platform and language neutral communication protocol that allows programs to communicate via standard Internet HTTP. SOAP is standardized by the W3C. • WSDL: WSDL (Web Services Description Language) is an XML-based language used to define web services and to describe how to access them. WSDL is a suggestion by Ariba, IBM and Microsoft for describing services for the W3C XML Activity on XML Protocols. • UDDI: UDDI (Universal Description, Discovery and Integration) is a directory service where businesses can register and search for web services.UDDI is a public registry, where one can publish and inquire about web services.
Java Applet? • What is Java applet? • What is Java servlet? • What is JavaServer Pages? • What is Java Web Start?
Java Applet • An applet is a software component that runs in the context of another program, for example a web browser. • A Java applet is an applet delivered in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine (JVM), or in Sun's AppletViewer, a stand-alone tool for testing applets.
Java Applet • Java applets are usually written in the Java programming language but they can also be written in other languages that compile to Java bytecode. • Applets are used to provide interactive features to web applications that cannot be provided by HTML. • Since Java's bytecode is platformindependent, Java applets can be executed by browsers for many platforms, including Windows, Unix, Mac OS and Linux.
Java bytecode • Java bytecode is the form of instructions that the Java virtual machine executes. • Each bytecode instruction is one byte in length. • Code: • 0: iconst_2 • 1: istore_1 • 2: iload_1 • 3: sipush 1000 • 6: if_icmpge 44 • 9: iconst_2 • 10: istore_2 • 11: iload_2 • 12: iload_1 • 41: goto 2 • 44: return
What Is a Servlet? • Web server response can be static or dynamic • Static: HTML document is retrieved from the file system and returned to the client • Dynamic: HTML document is generated by a program in response to an HTTP request • Java servlets are one technology for producing dynamic server responses • Servlet is a class instantiated by the server to produce a dynamic response