表单元素提交到服务器,通过request接收多个请求参数

时间:2022-10-13 15:24:03

1:html:

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <title>表单元素提交到服务器</title>
</head>
<body>
<form action="request_demo02.jsp" method="post" >
    用户名:<input type="text" maxlength="20" size="30" name="myName" id="myName" value="用户名"><br>
    密&nbsp;&nbsp;码:<input type="password" maxlength="10" size="20" name="myPassword" id="myPassword" value="密码"><br>
    兴&nbsp;&nbsp;趣:<input type="checkbox" name="inst" value="c语言">c语言&nbsp;
    <input type="checkbox" name="inst" value="c++语言">c++语言&nbsp;
    <input type="checkbox" name="inst" value="c#语言">c#语言&nbsp;
    <input type="checkbox" name="inst" value="object-c语言">object-c语言&nbsp;
    <input type="checkbox" name="inst" value="ASP.NET语言">ASP.NET语言<br>
    <input type="hidden" name="uid" value="隐层在客户端">
   <input type="submit"  value="提交" >&nbsp;
    <input type="reset"  value="重置"><br/>
</form>
</body>

</html>

  2:jsp

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>request接收多个请求参数</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("uid");
String myName = request.getParameter("myName");
String myPassword = request.getParameter("myPassword");
String inst[] = request.getParameterValues("inst");
%>
<h3>
编号:<%=id%></h3>
<h3>
姓名:<%=myName%></h3>
<h3>
密码:<%=myPassword%></h3>
<%
if (inst != null) {
%>
<h3>
兴趣:
<%
for (int i = 0; i < inst.length; i++) {
%>
<%=inst[i]%>、
<%
}
%>
</h3>
<%
}
%>
</body>
</html>