[问题]经济信息作业,教授给了一段java,但是每学过,求教!

软件和网站开发以及相关技术探讨
回复
diegowujun
帖子: 177
注册时间: 2007-08-10 6:45

[问题]经济信息作业,教授给了一段java,但是每学过,求教!

#1

帖子 diegowujun » 2007-11-25 22:11

import java.io.*;
import java.net.*;
public class TUC
{
public static void main(String[] s)
{
String firstLine;
Socket conn;
PrintStream out;
ServerSocket sock;
BufferedReader in;
try {
sock = new ServerSocket(80);
while (true)
{
// Wait for incoming tcp connection requests.
conn = sock.accept();
// Create input and output streams for the tcp connection.
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
out = new PrintStream(conn.getOutputStream());
// Read the first line of the http request.
firstLine = in.readLine();
if (firstLine.indexOf(" /testseite ") != -1)
{
// Find the HTTP version number.
int verPos = firstLine.indexOf("HTTP");
// Print HTTP-Header
out.println("HTTP/1.1 200 OK");
out.println("Content-Type: text/plain");
// Print HTTP-Body
out.println();
out.println("Herzlich willkommen!");
out.print("Sie verwenden HTTP version ");
out.println(firstLine.substring(verPos+5, verPos+8 ) ) ;
}
else
{
out.println("HTTP/1.1 200 OK");
out.println("Content-Type: text/plain");
out.println();
out.println("Die angeforderte Seite ist nicht
verfügbar.");
}
// Close the connection.
conn.close();
}
} catch (IOException ioX){ System.out.println(ioX); };
}
}


这段程序看不懂,谁能帮我讲一下,谢谢拉,最好详细点!
附带作业问题?
1.假设:这个服务是您从本地开始的.当它得到一个要求(request)"testseite",会发生什么,例如:当你在浏览器内键入:http://localhost/testseite
2.这个sever的response是怎么样的?在你的浏览器中是什么导致的这个?
3.当键入http://localhost/eineandereseite,会发生什么?
头像
Amankwah
帖子: 624
注册时间: 2006-10-16 7:24
来自: 安康/西安/广州
联系:

#2

帖子 Amankwah » 2007-11-25 22:24

经济信息作业??做这个??
读书取正,读易取变,读骚取幽,读庄取达,读汉文取坚,最有味卷中岁月。
与菊同野,与梅同疏,与莲同洁,与兰同芳,与海棠同韵,定自称花里神仙。
diegowujun
帖子: 177
注册时间: 2007-08-10 6:45

#3

帖子 diegowujun » 2007-11-25 22:30

是阿 没有办法,我们的教授经常出每教过的东西,我这个算简单的,还有被出过人家企业都每完成的项目!
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

#4

帖子 patrickhe » 2007-11-26 11:05

先把代码格式化一下
头像
yiller
帖子: 47
注册时间: 2007-09-28 2:33
来自: 重庆

#5

帖子 yiller » 2007-11-26 11:52

这是一个模拟一个简单WEB服务器的JAVA代码
通过套接字SOCKET监听来自80端口的访问

1.假设:这个服务是您从本地开始的.当它得到一个要求(request)"testseite",会发生什么,例如:当你在浏览器内键入:http://localhost/testseite
2.这个sever的response是怎么样的?在你的浏览器中是什么导致的这个?
响应
HTTP/1.1 200 OK
Content-Type: text/plain

Herzlich willkommen!
Sie verwenden HTTP version
1.1

也就是在浏览器窗口中显示
Herzlich willkommen!Sie verwenden HTTP version 1.1

3.当键入http://localhost/eineandereseite,会发生什么?
响应
HTTP/1.1 200 OK
Content-Type: text/plain

Die angeforderte Seite ist nicht verfügbar.

也就是在浏览器窗口中显示
Die ....那一句
diegowujun
帖子: 177
注册时间: 2007-08-10 6:45

#6

帖子 diegowujun » 2007-11-26 17:52

非常感谢,真是太热心了.
回复