54699f5a857d0f049fb9a46dfc943f10.ppt
- Количество слайдов: 26
Dynamic Web Programming Dr. Hsiang-Fu Yu National Taipei University of Education Original by Andy Powell
Overview n n ‘Dynamic’ = ‘Interactive‘ Web Form Common Gateway Interface (CGI) Server-side programming n n Client-side programming n n n Perl, PHP, ASP Javascript, Java Database connectivity Security 2
Why interact? Registration and requests for information n User feedback n Dynamic information n n Particular services might want to solicit contributions from people 3
Simple Web form <html> <head><title>simple form</title></head> <body> <form name="simple. Form" method=“get" action="simple. Handler. cgi"> Your email address: <input type="text" name="email"> <input type="submit" value="Submit"> </form> </body> </html> 4
Interacting With Web Forms n Steps n n Validate user input Process user input Generate a response These three steps may be done within n the Web browser (client-side) or the Web server (server-side) or some combination of both 5
Common Gateway Interface (CGI) n n Mechanism for a Web browser to send data to a Web server Allow browser to submit data to a program running on the server n n Program is often called a ‘CGI script’, typically written in Perl, PHP or ASP Or an execution binary file, compiled from a programming language such as C 6
CGI (cont. ) Used primarily form submission n Also be used to upload local files n ‘CGI’ URLs often contain ‘? ’ and ‘&’ characters n Output from CGI usually dynamic and therefore not cached n 7
CGI (cont. ) Web form Data sent using CGI Email File Results Database 8
CGI Programming - Perl n n n n Perl - Practical Extraction and Report Language Developed as general purpose (UNIX) utility Freely available on all platforms (though most often used under UNIX) Very good at manipulating textual data Interpreted - so fast development cycle A new Perl process is started for each new CGI script, so can be heavy on resources Many modules are freely available. See CPAN 9 <www. cpan. org>
What do I need to do n n n Install Perl (if you have a UNIX box, it is already installed. ) Install at least the CGI. pm Perl module from CPAN Configure your Web server to recognise files ending in ‘. pl’ (and ‘. cgi’) as Perl programs Buy one of the O’Reilly Perl books Visit <www. perl. org> and <www. perl. com> for tutorials, tips, and example code 10
CGI Programming - PHP n n n PHP - originally stood for Personal Home Pages C-style language HTML embedded scripting language n n PHP commands are embedded into the HTML page Hidden inside HTML comments Freely available - <www. php. net> Lots of code available 11
CGI Programming – PHP (cont. ) n n n Tight integration with databases particularly with My. SQL Quick development time for database driven applications Available under UNIX and Windows 12
What do I need to do Install PHP n Configure Web server to recognise files ending in ‘. php’, ‘. php 3’ and ‘. php 4’ as PHP-enabled pages n Buy the O’Reilly PHP book! n Visit <uk. php. net> and <www. phpwizard. net> for tutorials and sample code n 13
CGI Programming - ASP - Active Server Pages developed by Microsoft n HTML embedded scripting language n bundled in with MS Web server, e. g. IIS n Free and commercial UNIX version available (though not sure about compatibility) n GUI development tools available n 14
What do I need to do If you are using Microsoft Web server, it should all be ready to go. n If you are using a UNIX-based server, use Perl or PHP. n Check your Microsoft documentation n Visit <www. learnasp. com> n 15
Java. Script A browser programming language developed originally by Netscape n Simple language - not Java n Object-oriented approach n Embedded into HTML Web page between <script> and </script> tags n Can also <link> to external Java. Script file n 16
Java. Script and Forms n n Java. Script typically used in combination with forms to validate input Simple ‘event’ model, e. g. n n Use ‘on. Change’ or ‘on. Click’ methods to validate input before sending data to server-side CGI script Check that email addresses have ‘@’ in them Check that numbers contain only digits Check that mandatory fields are filled in 17
What do I need to do n n Nothing to install! Java. Script is supported by the major graphical browsers. Buy the O’Reilly Java. Script book. Visit <www. javascript. com> Warning - if you enhance your Web forms using Java. Script, make sure that they still work if Java. Script is disabled in the browser. 18
Java Developed by Sun - not standardised n Supposedly write-once/run anywhere, supposedly secure n Applications - stand-alone n Applets - embedded into browser n Interpreted by the Java Virtual Machine (JVM) n 19
Java (cont. ) n Applets have not taken off widely n n n Inconsistencies between JVM implementations Resource requirements Can be embedded into server-side applications - Java Server Pages Good support for database connectivity Good GUI development environments available 20
What do I need to do n n Install Java 2 SDK (Software Developers Kit) Try it by hand-coding using text editor initially Buy one of the O’Reilly Java books. Visit <java. sun. com/docs/books/tutorial/> for introduction to Java 21
Database Connectivity n Data from a Web form is n n processed directly and used as basis for response to users e-mailed to someone for further processing saved to a file (for further processing) processed/stored in a database 22
Open Database Connectivity (ODBC) Developed by Microsoft n Generic interface to databases n A CGI script developed using ODBC and SQL should work against any SQL database that offers an ODBC driver n n n Oracle, MS-Access, My. SQL Perl, PHP and ASP all offer access to databases via ODBC 23
Security Web sites that offer interaction through CGI scripts are inherently a little more insecure than sites that don’t n Watch out that n n n Critical files can’t be downloaded or overwritten Other programs can’t be uploaded or started unintentionally 24
Using Cookies n Remember preferences using cookies n n n Usually user name and password ‘cookies’ are small chunks of information that are stored in the browser but shared with the server Developed by Netscape but widely adopted Cookies should be only shared with the server that set them Support for cookies in Perl, PHP and ASP 25
Summary n n It is useful to know these basics Don’t need to develop all the CGI scripts yourself n n n Products like Microsoft Frontpage come with bundled suites of CGI utilities. Use externally hosted services Build on what’s already out there - chances are that someone has already developed the CGI script you need 26
54699f5a857d0f049fb9a46dfc943f10.ppt