HTML注册表单的简易实现

代码示例
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
	</head>
	<body>
		<form action="http://localhost:8080/html/register" method="post">
			用户名
			<input type="text" name="username" /><br>
			密码
			<input type="password" name="userpwd" /><br>
			确认密码
			<input type="password" /><br>
			性别:
			男<input type="radio" name="sex" value="男" />
			女<input type="radio" name="sex"  value="女" /><br>
			兴趣爱好:
			抽烟<input type="checkbox" name="hobby" value="smoke" />
			喝酒<input type="checkbox" name="hobby" value="drink"  />
			烫头<input type="checkbox" name="hobby" value="perm" /><br>
			学历:
			<select name="grade">
				<option value="z">专科</option>
				<option value="b" selected>本科</option>
				<option value="y">研究生</option>
			</select><br>
			简介:<br>
			<!--文本域没有value属性,用户填写的就是value-->
			<textarea rows="10" cols="50" name="introduction"></textarea><br>
			<input type="submit" value="注册" />
			<input type="reset" value="清空" />
		</form>
	</body>
</html>

在这里插入图片描述

form表单method属性:

1、get:采用get方式提交的时候,用户提交的信息会显示在浏览器的地址栏上。

<form action="http://localhost:8080/html/register" method="get">

地址栏显示:
在这里插入图片描述
http://localhost:8080/html/register?username=123&userpwd=123&sex=%E7%94%B7&hobby=smoke&hobby=drink&hobby=perm&grade=b&introduction=123
2、post:采用post方式提交的时候,用户提交的信息不会显示在浏览器地址栏上。

<form action="http://localhost:8080/html/register" method="post">

在这里插入图片描述
3、当用户提交的信息中含有敏感信息,例如:密码。建议采用post方式提交。
4、method属性不指定,或者指定get,这种情况下都是get。
只有当method属性指定为post的时候才是post请求。剩下所有的请求都是get请求。(默认为get)
5、post提交的数据格式和get还是一样的,只不过不在地址栏上显示出来。

原文地址:https://www.cnblogs.com/yu011/p/13501461.html