birt report qr code I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES in Font

Generating Data Matrix in Font I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES

CHAPTER 3 I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES
Print DataMatrix In None
Using Barcode creation for Font Control to generate, create DataMatrix image in Font applications.
www.OnBarcode.com
DataMatrix Encoder In None
Using Barcode creation for Font Control to generate, create Data Matrix image in Font applications.
www.OnBarcode.com
Figure 3-4. The browser sends the input data using either a GET or a POST method, and the server responds by echoing the input data.
Create Code 128B In None
Using Barcode printer for Font Control to generate, create Code 128A image in Font applications.
www.OnBarcode.com
Barcode Generation In None
Using Barcode generator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Listing 3-7 shows getAndPostExample.html, and Listing 3-8 shows the Java servlet that echoes the first name, middle name, and birthday back to the browser. Listing 3-7. getAndPostExample.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sending Request Data Using GET and POST</title> <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } }
Making Barcode In None
Using Barcode generation for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Paint QR Code 2d Barcode In None
Using Barcode creator for Font Control to generate, create QR Code image in Font applications.
www.OnBarcode.com
CHAPTER 3 I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES
Make ANSI/AIM Code 39 In None
Using Barcode encoder for Font Control to generate, create Code39 image in Font applications.
www.OnBarcode.com
ISSN - 10 Printer In None
Using Barcode creation for Font Control to generate, create ISSN - 10 image in Font applications.
www.OnBarcode.com
function createQueryString() { var firstName = document.getElementById("firstName").value; var middleName = document.getElementById("middleName").value; var birthday = document.getElementById("birthday").value; var queryString = "firstName=" + firstName + "&middleName=" + middleName + "&birthday=" + birthday; return queryString; } function doRequestUsingGET() { createXMLHttpRequest(); var queryString = "GetAndPostExample "; queryString = queryString + createQueryString() + "&timeStamp=" + new Date().getTime(); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", queryString, true); xmlHttp.send(null); } function doRequestUsingPOST() { createXMLHttpRequest(); var url = "GetAndPostExample timeStamp=" + new Date().getTime(); var queryString = createQueryString(); xmlHttp.open("POST", url, true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); xmlHttp.send(queryString); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { parseResults(); } } } function parseResults() { var responseDiv = document.getElementById("serverResponse"); if(responseDiv.hasChildNodes()) { responseDiv.removeChild(responseDiv.childNodes[0]); }
Decode Data Matrix ECC200 In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Print DataMatrix In None
Using Barcode maker for Office Excel Control to generate, create Data Matrix 2d barcode image in Office Excel applications.
www.OnBarcode.com
CHAPTER 3 I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES
QR Code ISO/IEC18004 Generator In Objective-C
Using Barcode generation for iPhone Control to generate, create QR Code image in iPhone applications.
www.OnBarcode.com
Create Barcode In Objective-C
Using Barcode maker for iPad Control to generate, create Barcode image in iPad applications.
www.OnBarcode.com
var responseText = document.createTextNode(xmlHttp.responseText); responseDiv.appendChild(responseText); } </script> </head> <body> <h1>Enter your first name, middle name, and birthday:</h1> <table> <tbody> <tr> <td>First name:</td> <td><input type="text" id="firstName"/> </tr> <tr> <td>Middle name:</td> <td><input type="text" id="middleName"/> </tr> <tr> <td>Birthday:</td> <td><input type="text" id="birthday"/> </tr> </tbody> </table> <form action="#"> <input type="button" value="Send parameters using GET" onclick="doRequestUsingGET();"/> <br/><br/> <input type="button" value="Send parameters using POST" onclick="doRequestUsingPOST();"/> </form> <br/> <h2>Server Response:</h2> <div id="serverResponse"></div> </body> </html>
Recognizing Universal Product Code Version A In Visual Studio .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Paint Code 39 In None
Using Barcode generator for Online Control to generate, create ANSI/AIM Code 39 image in Online applications.
www.OnBarcode.com
CHAPTER 3 I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES
Making Code 39 In Java
Using Barcode generation for Java Control to generate, create Code 39 Full ASCII image in Java applications.
www.OnBarcode.com
Generate EAN 128 In C#.NET
Using Barcode creation for .NET Control to generate, create UCC.EAN - 128 image in .NET applications.
www.OnBarcode.com
Listing 3-8. Echoing the First Name, Middle Name, and Birthday Back to the Browser package ajaxbook.chap3; import import import import java.io.*; java.net.*; javax.servlet.*; javax.servlet.http.*;
Code 128 Code Set C Decoder In VS .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Creating DataMatrix In Java
Using Barcode creator for Eclipse BIRT Control to generate, create DataMatrix image in Eclipse BIRT applications.
www.OnBarcode.com
public class GetAndPostExample extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response, String method) throws ServletException, IOException { //Set content type of the response to text/xml response.setContentType("text/xml"); //Get the user's input String firstName = request.getParameter("firstName"); String middleName = request.getParameter("middleName"); String birthday = request.getParameter("birthday"); //Create the response text String responseText = "Hello " + firstName + " " + middleName + ". Your birthday is " + birthday + "." + " [Method: " + method + "]"; //Write the response back to the browser PrintWriter out = response.getWriter(); out.println(responseText); //Close the writer out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Process the request in method processRequest processRequest(request, response, "GET"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Process the request in method processRequest processRequest(request, response, "POST"); } }
Barcode Creator In Visual Basic .NET
Using Barcode creation for .NET framework Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
Quick Response Code Generator In VS .NET
Using Barcode drawer for VS .NET Control to generate, create QR Code ISO/IEC18004 image in VS .NET applications.
www.OnBarcode.com
CHAPTER 3 I COMMUNICATING WITH THE SERVER: SENDING REQUESTS AND PROCESSING RESPONSES
Let s examine the server-side code first. This example uses a Java servlet to handle the request, although you can use any server-side technology such as PHP, CGI, or .NET. Java servlets must define a doGet method and a doPost method, with each method being called according to the request method. In this example, both doGet and doPost will call the same method, processRequest, to handle the request. The processRequest method starts by setting the content type of the response to text/xml, even though in this example XML isn t actually used. The three input fields are retrieved from the request object by using the getParameter method. A simple sentence is built using the first name, middle name, and birthday, along with the type of request method. The sentence is then written to the response output stream, and finally the response output stream is closed. The browser-side JavaScript is again similar to previous examples but with a few added twists. A utility function named createQueryString is responsible for encoding the input parameters as a query string. The createQueryString function simply retrieves the input values for the first name, middle name, and birthday and appends them as name/value pairs. Each name/value pair is separated by an ampersand. This function returns the query string, allowing it to be reused by both the GET and POST operations. Clicking the Send Parameters Using GET button calls the doRequestUsingGET function. This function, like many of the previous examples, starts by calling the function that creates an instance of the XMLHttpRequest object. Next, the query string that encodes the input values is created. The request endpoint for this example is the servlet named GetAndPostExample. The query string is created by concatenating the query string returned by the createQueryString function to the request endpoint, separated by a question mark. The JavaScript continues as you ve seen before. The XMLHttpRequest object s onreadystatechange property is set to use the handleStateChange function. The open() method specifies that this is a GET request and the endpoint URL, which in this case contains the encoded parameters. The send() method sends the request to the server, and the handleStateChange function handles the server response. The handleStateChange function calls the parseResults function upon successful completion of the request. The parseResults function retrieves the div element that contains the server s response and stores it in a local variable named responseDiv. Any previous server results are first removed from responseDiv by using its removeChild method. Finally, a new text node is created containing the server s response and is appended to responseDiv. The techniques for using the POST method instead of GET are identical except for how the request parameters are sent to the server. Recall that when using GET, the name/value pairs are appended to the destination URL. The POST method sends the same query string as part of the request body. Clicking the Send Parameters Using POST button calls the doRequestUsingPOST function. Like the doRequestUsingGET function, it starts by creating an instance of the XMLHttpRequest object. The script continues by creating the query string that contains the parameters to be sent to the server. Note that the query string is not concatenated with the destination URL. The XMLHttpRequest object s open() method is invoked, this time specifying POST as the request method in addition to specifying the bare destination URL. The onreadystatechange property is set to the handleStateChange function, allowing the response to be processed in the same way as the GET method. To ensure that the server knows that the request parameters can be found within the request body, the setRequestHeader is called, setting the Content-Type
Copyright © OnBarcode.com . All rights reserved.