javaweb入门之表单提交与HttpSeverletRequest

1.下面是一个表单,把它以post方式提交到addchuli的severlet:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>添加联系人</title>
</head>
<body>
	<center><header>添加联系人</header></center>
	<form action="/webproject_contact/addchuli" method="post">
	<table align="center" border="1" width="700px">
	<tr>
		<th>姓名</th>
		<td><input type="text" name="name"></td>
	</tr>
	<tr>
		<th>性别</th>
		<td>
			<input type="radio" value="man">男
			<input type="radio" value="feman">女
		</td>
	</tr>
	<tr>
		<th>年龄</th>
		<td><input type="text" name="age"></td>
	</tr>
	<tr>
		<th>电话</th>
		<td><input type="text" name="phone"></td>
	</tr>
	<tr>
		<th>邮箱</th>
		<td><input type="text" name="email"></td>
	</tr>
	<tr>
		<th>qq</th>
		<td><input type="text" name="qq"></td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" value="保存">&nbsp;<input type="reset" value="重置"></td>
	</tr>
</table>
</form>
</body>
</html>

2.当我部署好后,浏览器客户端输入http://localhost:8080/webproject_contact/add.html,就会访问到部署在服务器上的资源在这里插入图片描述
在这里插入图片描述
3.下面是severlet代码

// 把表单中的name项打印到控制台
public class addchuli extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		System.out.println(name);	
	}
}

4.在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
tomcat服务器将我此次的请求的请求行,请求头,实体内容都封装成HttpSeverletRequest对象,服务器调用资源代码的doPost方法,并将封装好的HttpSeverletReqest对象传入,我们可以在方法内部通过传入的对象获取表单信息。
结果:在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值