GET /index.html HTTP/1.0 \ r \ n \ r \ n in Java Integration pdf417 in Java GET /index.html HTTP/1.0 \ r \ n \ r \ n

GET /index.html HTTP/1.0 \ r \ n \ r \ n use jar pdf417 writer toinsert pdf 417 with java Bar Code Scanner Environments Here GET is the r PDF 417 for Java equest keyword, /index.html is the le requested, and HTTP/1.0 indicates the protocol and version number of the protocol to be used.

Finally, the characters \ r \ n \ r \ n indicate the two carriage return/linefeed pairs that terminate the line. The next code snippet from run() obtains the request line sent from the client by invoking the readLine() method of BufferedReader. Then the request text is broken into tokens with the split() method in the String class (see 10).

The tokens are checked to determine if the client sent the GET command and, if so, to obtain the name of the le that the client is requesting.. . . .

In the run( ) method in Worker . . .

// First read the message line from the client String client-str = client-in.readLine ();. A Java web server System.out.printl n ("Client message: " + client-str); // Split the message into substrings.

String [] tokens = client-str.split(" "); // Check that the message has a minimun number of words // and that the first word is the GET command. if ((tokens.

length >= 2) && tokens[0].equals ("GET")) { String file-name = tokens[1]; // Ignore the leading "/" on the file name. if (file-name.

startsWith ("/")) file-name = file-name.substring (1); // If no file name is there, use index.html default.

if (file-name.endsWith ("/") . file-name.equals jvm pdf417 ("")) file-name = file-name + "index.html"; // Check if the file is hypertext or plain text String content-type; if (file-name.

endsWith (".html") . file-name.endsWi th (".htm")) { content-type = "text/html";.

} . . .

. If the request fr om the client is valid, we then read the local le that the client is requesting and return it to the client. As shown in the following code, to read the le we rst obtain a FileInputStream for the le. We send text messages back to the client using the PrintWriter methods.

We note that the PrintWriter methods don t throw IOException and instead the class offers the checkError() method, which returns true if an IOException occurred. For the sake of brevity, we did not check for errors after every print invocation. (In the DataWorker class in 15, we place the print invocations in utility methods that check for errors and throw exceptions when they occur.

) The line HTTP/1.0 200 OK \ r \ n gives the protocol and version number of the return message followed by the 200 code number that indicates that the le has been found successfully and will be sent. This is followed by the le s modi cation date, an identi cation of the server, the length of the le and the le type (e.

g. text/html ). Finally, the whole le is sent in one big byte array via the write() method of OutputStream.

If the le is not available, the program sends the 404 Object Not Found error message, which is a common one for web users. If the request line had problems, a 400 Bad Request error message is sent..

14.3 Hypertext Tr jdk PDF 417 ansfer Protocol (HTTP). . . .

Continue in run() method in Worker . . .

// Now read the file from the disk and write it to // the output stream to the client. try { // Open a stream to the file. FileInputStream file-in = new FileInputStream (file-name); // Send the header.

pw-client-out.print ("HTTP/1.0 200 OK \ r \ n"); File file = new File (file-name); Date date = new Date (file.

lastModified ()); pw-client-out.print ("Date: " + date + " \ r \ n"); pw-client-out.print ("Server: MicroServer 1.

0 \ r \ n"); pw-client-out.print ("Content-length: " + file-in.available () + " \ r \ n"); pw-client-out.

print ("Content-type: " + content-type + " \ r \ n \ r \ n"); // Create a byte array to hold the file. byte [] data = new byte [file-in.available ()]; file-in.

read (data); // client-out.write (data); // client-out.flush (); // file-in.

close (); // Read file into byte array Write it to client stream Flush output buffer Close file input stream. } catch (FileNotF jvm pdf417 2d barcode oundException e) { // If no such file, then send the famous 404 message. pw-client-out.println ("404 Object Not Found"); } } else { pw-client-out.

println ("400 Bad Request"); } } catch (IOException e) { System.out.println ("I/O error " + e); }.

// Close client s ocket. try { fClient.close (); } catch (IOException e) { System.

out.println ("I/O error " + e);.
Copyright © . All rights reserved.