【Java Web】在html界面中提交表单,由jsp进行接收并展示[jsp的接收使用的是jsp内置对象] 【上课记录】

9月27号【上午1-2节java web课】

1、jsp+html【简单提交表单】

html代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action = "/lyy_1.jsp">
	输入项:<input type = "text" name = "n"/>
	<input type = "submit" value = "提交" >	
	</form>

</body>
</html>

jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<% String n = request.getParameter("n");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<%
	out.print("你好");
	%>
	<%=n%>

</body>
</html>

截图展示

在这里插入图片描述

在这里插入图片描述

2、html+jsp【提交个人简历】

html代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action = "lyy_1.jsp">
	姓名:<input type = "text" name = "n"/><br>
	密码:<input type = "password" name = "p"/><br>
	
	性别:
	<input type = "radio" name = "g" value = "男"/>男 
	<input type = "radio" name = "g" value = "女"/>女<br>
	
	爱好:
	<input type = "checkbox" name = "l" value = "音乐"/>音乐
	<input type = "checkbox" name = "l" value = "运动"/>运动
	<input type = "checkbox" name = "l" value = "电影"/>电影
	<input type = "checkbox" name = "l" value = "编程"/>编程<br>
	
	班级:
	<select name = "c">
		<option value = "2006班">2006班</option>
		<option value = "2007班">2007班</option>
	</select><br>
	
	个人说明:<br>
	<textarea name = "i" rows = "4" cols = "100">请填写个人说明</textarea><br>

	
	<input type = "submit" value = "提交" >	
	<input type = "reset">
	</form>

</body>
</html>

jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<% String [] like = request.getParameterValues("l");%>
<%-- <% String sex = request.getParameter("g");%> --%> 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	姓名:<%=request.getParameter("n")%><br>
	密码:<%=request.getParameter("p")%><br>
	性别:<%=request.getParameter("g")%><br>
	<%-- 
	<% if (sex == "0")  {out.print("男");}%>
	<% if (sex == "1")  {out.print("女");}%>
	--%>
	爱好:
	<% for (int i = 0; i <like.length; i++) {out.print(like[i]+",");} %><br>
	班级:<%=request.getParameter("c")%><br>
	个人说明:<%=request.getParameter("i")%>

</body>
</html>

运行截图:
在这里插入图片描述
在这里插入图片描述

  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bessie_Lee_gogogo

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值