1 / 14

Client side & Server side scripting

Client side & Server side scripting. How do Web server works

lesleys
Download Presentation

Client side & Server side scripting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Client side & Server side scripting How do Web server works First, it's important to note that this is a two-sided story. Web servers are responsible for storing and exchanging information with other machines. Because of this, at least two participants are required for each exchange of information: a client, which requests the information, and a server, which stores it. Each side also requires a piece of software to negotiate the exchange of data; in the case of the client, a browser like Netscape or Internet Explorer is used.

  2. Server data exchange • A simple exchange between the client machine and Web server goes like this: 1. The client's browser dissects the URL in to a number of separate parts, including address, path name and protocol. • 2. A Domain Name Server (DNS) translates the domain name the user has entered in to its IP address, a numeric combination that represents the site's true address on the Internet (a domain name is merely a "front" to make site addresses easier to remember). • 3. The browser now determines which protocol (the language client machines use to communicate with servers) should be used. Examples of protocols include FTP, or File Transfer Protocol, and HTTP, Hypertext Transfer Protocol. • 4. The server sends a GET request to the Web server to retrieve the address it has been given. For example, when a user types http://www.example.com/1.jpg, the browser sends a GET 1.jpg command to example.com and waits for a response. The server now responds to the browser's requests. It verifies that the given address exists, finds the necessary files, runs the appropriate scripts, exchanges cookies if necessary, and returns the results back to the browser. If it cannot locate the file, the server sends an error message to the client. • 5. The browser translates the data it has been given in to HTML and displays the results to the user. This process is repeated until the client browser leaves the site.

  3. Client side scripting • Most web applications involve both client-side and server-side script. Client-side script is often used to program the user interface for an application - for example, to change a web page's text dynamically, respond to user actions such as button clicks, and perform such client-oriented tasks as input validation. Client-side script executes locally in the browser, which provides the user with a lively and responsive interface.

  4. Client side scripting • Client-side scripts are programs that you write and attach to HTML documents that run on a user's browser while he is viewing said documents. • When developing ASP.NET server controls you should ask yourself how you could enhance the usability through the use of client-side script. Once you have identified these areas, all that remains is to augment the server control so that it emits the proper client-side script. • There are two types of client-side script ASP.NET server controls can emit: • Client-side script blocks • Client-side HTML attributes

  5. Writing client side scripts • A client side script using VB script. • A client side script using Java script.

  6. Advantage & disadvantage of Client side scripting. • Advantages • Client-side scripts offer numerous advantages, including: • Allow for more interactivity by immediately responding to users' actions. • Execute quickly because they don't require a trip to the server May improve the usability of Web sites for users whose browsers support scripts. • Can give developers more control over the look and behavior of their Web applications. • Can be substituted with alternatives (for example, HTML) if users' browsers do not support scripts, are reusable and obtainable from many free resources such as Hotscripts.com and Javascript.com

  7. Advantage & disadvantage of Client side scripting. • Disadvantages Client-side scripts also create additional worries, including: • Not all browsers supportscripts, therefore, users might experience errors if no alternatives have been provided. • Different browsers and browser versions support scripts differently, thus more quality assurance testing is required. • More development time and effort might be required (if the scripts are not already available through other resources).

  8. Server side script • Server-side scripting is about "programming" the behavior of the server. This is called server-side scripting or server scripting. • Normally when a browser requests an HTML file, the server returns the file, but if the file contains a server-side script, the script inside the HTML file is executed by the server before the file is returned to the browser as plain HTML.

  9. Server side script • What can Server Scripts Do? • Dynamically edit, change or add any content to 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 • Provide security since your server code cannot be viewed from a browser Important: Because the scripts are executed on the server, the browser that displays the ASP/PHP file does not need to support scripting at all!

  10. Writing server side script • If we're going to place any kind of server-side script within our web page source files, then we need to label the scripts – so that the server can identify them as server-side scripts and hence arrange for them to be interpreted correctly. There are two ways to label server-side scripts: • Use the <% … %> server script delimiters, which denote ASP code • Use the HTML <SCRIPT> tag, specifying the RUNAT=SERVER attribute within the tag. If a tag like this is found within an .asp file, then it is treated as ASP. If such a tag is found within an .htm file, then it is treated as a non-ASP server-side script.

  11. Using your preferred HTML editor, start a new document. Type the following code into it: <HTML> <HEAD> <TITLE>Writing the Current Date to the Page with ASP Script</TITLE> </HEAD> <BODY BGCOLOR=GRAY> <H2>Date Confirmation</H2> <SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER> Response.Write(Date) </SCRIPT> </BODY> </HTML> • Save the file as DateConf1.asp in your Inetpub\wwwroot\BegASPFiles directory.

  12. Getting info from user • To read the values of a form field, you need to use the request object. The request object has use mainly two collections • Form collections When to use QueryString When the form field values are being passed through querystring, and if you create a form with METHOD=GET, this is the request collection you’ll want to use Form When the form is created with its METHOD property set to POST, use this request collection.

  13. Getting info from user • User Input • The Request object may be used to retrieve user information from forms. • Form example: • <form method="get" action="simpleform.asp"> First Name: <input type="text" name="fname" /> <br /> Last Name: <input type="text" name="lname" /> <br /><br /> <input type="submit" value="Submit" /> </form> User input can be retrieved in two ways: With Request.QueryString or Request.Form. • Request.QueryString • The Request.QueryString command is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send. • If a user typed "Bill" and "Gates" in the form example above, the URL sent to the server would look like this: • <body> Welcome • <% response.write(request.querystring("fname")) response.write(" " & request.querystring("lname")) %> </body>

  14. Using info obtained from user • <html><body><form action="demo_reqquery.asp" method="get">Your name: <input type="text" name="fname" size="20" /><input type="submit" value="Submit" /></form><%dim fnamefname=Request.QueryString("fname")If fname<>"" Then      Response.Write("Hello " & fname & "!<br />")      Response.Write("How are you today?")End If%></body></html>

More Related