Networking Java Solutions Homework Extract the filename from the request line

subject Type Homework Help
subject Pages 4
subject Words 515
subject Authors James F. Kurose, Keith W. Ross

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Solutions for Programming Assignment 1
Below are the solutions for the Web Server lab. There are two classes, HttpRequest and
WebServer.
HttpRequest.java
import java.io.* ;
public void run() {
try {
processRequest();
} catch (Exception e) {
System.out.println(e);
}
}
message.
String requestLine = br.readLine();
page-pf2
// Extract the filename from the request line.
StringTokenizer tokens = new
StringTokenizer(requestLine);
fis = new FileInputStream(fileName);
} catch (FileNotFoundException e) {
fileExists = false ;
}
// Debug info for private use
System.out.println("Incoming!!!");
0) {
System.out.println(headerLine);
}
// Construct the response message.
String statusLine = null;
String contentTypeLine = null;
entityBody = "<HTML>" +
"<HEAD><TITLE>Not Found</TITLE></HEAD>" +
"<BODY>Not Found</BODY></HTML>";
}
page-pf3
// Send the status line.
os.writeBytes(statusLine);
os.writeBytes(entityBody) ;
}
// Close streams and socket.
os.close();
br.close();
socket.close();
}
os.write(buffer, 0, bytes);
}
}
private static String contentType(String fileName)
{
if(fileName.endsWith(".htm") ||
fileName.endsWith(".html")) {
return "text/html";
}
page-pf4
Exception {
// Get the port number from the command line.
int port = (new Integer(argv[0])).intValue();
// Establish the listen socket.
ServerSocket socket = new ServerSocket(port);
}
}
}

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.