Web forms and server side scripting
-
Upload
sawsan-slii -
Category
Internet
-
view
128 -
download
0
Transcript of Web forms and server side scripting
Web content HTML documents are static Dynamic content :
User side programming (JavaScript, CSS, Ajax, JQuery……)
Server side programming (PHP, ASP and ASP.Net, JSP, Python….)
Why Server Side Programming? Accessibility :Any one can reach Internet. Manageability :Does not require distribution of application code Security :Source code is not exposed Scalability : (تطور)Web-based 3-tier architecture can scale out
History of web dynamic content Common Gateway Interface (CGI) was the
first generation approach to providing dynamic web content (used scripts)
Numerous second generation alternatives were invented (FastCGI, mod_Perl, NSAPI, ISAPI, Java Servlets…)
Scripting, the third generation approach
Scripting, the third generation approach Embed simple code in HTML pages The HTML pages use the code to decide what
elements to display and what data should be displayed.
Classes and/or subroutines can be called to compute information for inclusion in the web page.
This is know as « scripting ».
Scripting languages or compiled Scripting languages Compiled languages
Server Side Includes (SSI)PerlPHP ASP (VBScript)Python
CC++ASP.NetJava ServletJava Server Pages
Some approaches to Scripting JavaServer Pages (JSP) by Sun MicroSystems
Hypertext Preprocessor (PHP): open source
Cold Fusion (CFML) by Macromedia
Active Server Pages (ASP and ASP.Net) by MicroSoft
Criteria affecting Scripting choice Web Server availability
Knowledge of language
Scalability and efficiency
Personal preference
JSP (Java Server Pages( Java-based technology that simplifies the
development of dynamic websites Designed around the Java Philosophy Packaged with J2EE It separates presentation aspects from
programming logic contained in the code.
J2EE Technology Web container (application server) EJB container Servlets : JSP pages running in webServers JSP: JavaServer Pages Apples, XML, JDBC, …….
JSP Basics Individual JSP pages are text files stored on the web
server. When a page is first required, then JSP Engine uses
the page to generate a Servlet. The compiled Servlet is saved and used to serve
additional requests. When a page is modified, the appropriate Servlet is
regenerated. Precompilation is also possible
A simple JSP code
New.java.util.Date().ToString(): creates a date Object and converts it to a String that can be displayed
What is PHP? Open source Server-Side Scripting language
designed specifically for the web. Conceived in 1994. Supports a wide-range of databases. Perl and C like syntax. Designed similar to ASP: you embed
commands into your web pages.
What is PHP? Commands are preprocessed by Php
processor and appropriate HTML is sent to the web server.
Platoform independant Easy to learn Usually associated to MySQL database (a
relational free DBMS, can run on Unix, Windows, and Mac OS).
ASP.Net Based on .Net Framework and the common
language runtime (CLR) Compiled language MicroSoft Only Platforms
Steps to Form Processing Script Creating the HTML code for the form<form action="myform.php" method="post">
<!-- form fields here -->
</form>
The “action” specifies what page to submit the form to.
The “method” indicates how the form is submitted :Get and Post.
Most of the time, forms will use the “post” method.
Steps to Form Processing Script<form action="myform.php" method="post"> Which is your favorite movie?<input type="text" name="formMovie"
maxlength="50"> <input type="submit" name="formSubmit"
value="Submit"></form>
Steps to Form Processing Script Getting the form data:
The input of type “text” is just a single line field to type in some text. We give it a name of “formMovie” .
You have a button submit that submits the whole form once clicked on.
Steps to Form Processing Script<?php if($_POST['formSubmit'] == "Submit") { $varMovie = $_POST['formMovie']; }?><form action="myform.php" method="post"> Which is your favorite movie?<input type="text" name="formMovie" maxlength="50"> <input type="submit" name="formSubmit" value="Submit"> </form>
Steps to Form Processing Script Validating the input:Suppose we have a user who forgot to enter one of the fields?
We need to validate the form to make sure it’s complete and
filled out with valid information.
Steps to Form Processing Script<?phpif($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['formMovie'])) { $errorMessage .= "<li>You forgot to enter a movie!</li>"; }
Steps to Form Processing Script if(empty($_POST['formName'])) { $errorMessage .= "<li>You forgot to enter a
name!</li>"; } $varMovie = $_POST['formMovie']; $varName = $_POST['formName'];
Steps to Form Processing Script if(!empty($errorMessage)) { echo("<p>There was an error with your
form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } } ?>
PHP: How to connect to the server?
Option 1: Website on a hosted server Option 2: Install PHP on your computer Option 3: XAMPP
Website on a hosted server Create a file in Notepad (or similar text editor)
named test.php Insert the following code in the file:
<?php echo "Hello World!"; ?>
Upload the file to your web host. Open the file in your browser. If the browser writes "Hello World!" your web host
supports PHP and you are ready to go. Otherwise contact your hosting provider for more information.
XAMPP Open the program XAMPP Control Panel Start the Apache server and the MySql server: Create a file in Notepad named test.php . Insert the following code in the file:<?php echo "Hello World!"; ?> Save the file in the folder "c:\xampp\htdocs". Open the file in your browser with the address
http://localhost/test.php. If the browser writes "Hello World!" the installation is
successful, and you're ready to run PHP on your computer.