【发布时间】:2014-10-08 14:33:33
【问题描述】:
我编写了一个简单的代码,它是一个小巧的 Web 服务器。我想在客户端输入loalhost:8181/pic 时显示图片,但是当我 String str = in.readLine() str 仅显示 localhost:8181 我如何在他的浏览器中找到客户端输入localhost:8181/pic ?有我的简单代码:
protected void start() {
ServerSocket s;
System.out.println("Webserver starting up on port 80");
System.out.println("(press ctrl-c to exit)");
try {
// create the main server socket
s = new ServerSocket(8181);
} catch (Exception e) {
System.out.println("Error: " + e);
return;
}
System.out.println("Waiting for connection");
for (;;) {
try {
Socket remote = s.accept();
System.out.println("Connection, sending data.");
BufferedReader in = new BufferedReader(new InputStreamReader(
remote.getInputStream()));
PrintWriter out = new PrintWriter(remote.getOutputStream());
String method = in.readLine();
out.flush();
remote.close();
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
【问题讨论】:
标签: java sockets http webserver