getparameterNames()用法

<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<body>
<form action="byte.jsp" method="post">
登陸號:<input type="text" name="uname"><br>
密碼:<input type="password" name="password"><br>
愛好:<br><input type="checkbox" name="**hobby" value="籃球">籃球
<input type="checkbox" name="**hobby" value="足球">足球
<input type="checkbox" name="**hobby" value="排球">排球
<input type="submit" value="提交"><br>
</form>
<a href="byte.jsp?uname=xiaogu"/>byte.jsp
</body>
</html>

另一頁面代碼:


<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*" %>
<%
Enumeration enu=request.getParameterNames();//獲得參數名
while(enu.hasMoreElements())//測試此枚舉是否包含更多元素。
{
String name=(String)enu.nextElement();.//接收過來的是個對象,需要把它轉化爲字符串。
if(name.startsWith("**"))//以兩個星號開頭的,是個數組需要下面方法接受值。
{
String temp[]=request.getParameterValues(name);
%>
<h1><%=name%>-->
<%
for(int i=0;i<temp.length;i++)
{
%>
<%=temp[i]%>
<%
}
%>
</h1>
<%
}
else
{
%>
<h1><%=name%></h1>-->
<%=request.getParameter(name)%></h1>
<%
}
%>
</h1>
<%
}
%>

發佈了60 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章