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>
运行截图: