Networking Java Solutions Homework Extract the filename from the request line

Document Type
Homework Help
Book Title
Computer Networking: A Top-Down Approach 6th Edition
Authors
James F. Kurose, Keith W. Ross
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();
// 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>";
}
// 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";
}
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.