自己写的Socket程序。然后自己访问。用post提交连接了两次。
假如我用用post提交,打印请求信息,可以看到先是post一次,然后get一次。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>