Html_表单提交

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
		<title>表单格式化_Post和Get提交</title>
	</head>
	<body>
		<h1>表单格式化_Post和Get提交</h1>
		<form action="http://127.0.0.1:9090" method="post">
			<table border="1" bordercolor="#ff00ff" width="350" cellpadding="10" cellspacing="1">
	<tr>
		<th colspan="2">用户注册</th>
	</tr>
	<tr>
		<td>用户名:</td>
		<td><input type="text" name="user"/></td>
	</tr>
	<tr>
		<td>密码:</td>
		<td><input type="password" name="psw"/></td>
	</tr>
	<tr>
		<td>确认密码:</td>
		<td><input type="password" name="repsw"/></td>
	</tr>
	<tr>
		<td>性别:</td>
		<td>
		 <input type="radio" name="sex" value="boy"/>男
		  <input type="radio" name="sex" value="girl" checked="checked"/>女
		</td>
	</tr>
	<tr>
		<td>兴趣:</td>
		<td>
		 <input type="checkbox" name="interest" value="Java" checked="checked"/>Java
		 <input type="checkbox" name="interest" value="html5"/>html5
		 <input type="checkbox" name="interest" value="易语言"/>易语言
		</td>
	</tr>
	<tr>
		<td>国家:</td>
		<td>
		 <select name="country">
		  <option value="none">请选择国家</option>
		  <option value="CN" selected="selected">中国</option>
		  <option value="USA">美国</option>
		  <option value="UK">英国</option>
	 </select>
		</td>
	</tr>
	<tr>
		<th colspan="2">
		 <input type="reset" value="重置" />
		 <input type="submit" value="提交注册"/>
		</th>
	</tr>
			</table>
		</form>
	</body>
</html>

服务端源码
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class RegServerSocketDemo {
	public static void main(String[] args) throws Exception {
		method_1();
	}
	private static void method_1() throws Exception {
		/*方法说明:
		*写个服务端,读取IE注册页面,并反馈消息,打印表单两种方式提交的过来数据!
		*/
		ServerSocket ss=new ServerSocket(9090);
		Socket s=ss.accept();
		//用输入流读取表单提交过来的数据
		InputStream in=s.getInputStream();
		byte[] buf=new byte[1024];
		int len=in.read(buf);
		System.out.println(new String(buf, 0, len));
		//反馈给浏览器注册成功的数据!
		PrintWriter out=new PrintWriter(s.getOutputStream(),true);
		out.println("注册成功!");
		//关流
		s.close();
		ss.close();
	}
}
/*
这个是get提交数据时IE地址栏:
http://127.0.0.1:9090/?user=abc&psw=555
&repsw=555&sex=boy&interest=Java&country=CN

这个是服务器收到消息:
GET /?user=abc&psw=555&repsw=555&sex=boy&interest=Java&country=CN HTTP/1.1
Accept: 太多了省略了...
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; 太多了省略了...)
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:9090
Connection: Keep-Alive

*/

/*
这个是Post提交数据时IE地址栏:
http://127.0.0.1:9090/

这个是服务器收到消息:(请求行,请求消息头,空行,请求体)
POST / HTTP/1.1
Accept: 太多了省略了...
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0太多了省略了......)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:9090
Content-Length: 60
Connection: Keep-Alive
Cache-Control: no-cache

user=abc&psw=666&repsw=666&sex=girl&interest=Java&country=CN

*/
/*
get提交和post提交的区别:
1,get提交内容都显示在地址栏里面,而post提交不显示
2,get提交对敏感信息不安全
3,get提交不能提交大数据,因为地址栏存储长度有限
4,get提交在请求行中,post提交在请求体中
5,服务器对中文的解码方式也有区别
	(两种提交方式通用:通过iso8859-1解码后是乱码,对乱码进行一次iso8859-1编码,
		再进行对应的中文解码)
	(但是对于post提交,还有一种处理乱码的方式:
		用服务器的request对象中的setCharacterEncoding方法,
		可以直接设置指定的中文码进行中文的解析!
		注意:该方法仅对请求体中的数据解码!)
*/
/*
和服务器交互的三种方式:
1,地址栏即URL
2,超链接
3,表单提交
无论客户端还是服务端都始终要对提交数据进行增强型的校验!
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值