81,092
社区成员
发帖
与我相关
我的任务
分享
public class Login {
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(10000);
while(true) {
Socket s = ss.accept();
System.out.println(s.toString());//打印了两次
new Thread(new UserThread(s)).start();
}
}
}
class UserThread implements Runnable {
private Socket s;
public UserThread(Socket s) {
this.s = s;
}
public void run() {
try {
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
out.println("欢迎来访问<br />");
out.println("哈哈,怎么连接两次啊");
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册页面</title>
</head>
<body>
<!-- <div>
<form action="http://127.0.0.1:10000" method="get">
姓名<input name="name" type="text" /><br />
年龄<input name="age" type="text" /><br />
<input type="submit" value="get提交" />
</form>
</div><br /> -->
<div>
<form action="http://127.0.0.1:10000" method="post">
姓名<input name="name" type="text" /><br />
年龄<input name="age" type="text" /><br />
<input type="submit" value="post提交" />
</form>
</div>
</body>
</html>
public void run() {
try {
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}