JAVA-JSP内置对象之request获得所有的参数名称


 

相关资料:
《21天学通Java Web开发》

 

获得所有的参数名称
1.request对象的getParameterNames()方法可以获得所有的参数名称。

RequestForm2.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
 2 <html>
 3 <head>
 4   <title>表单</title>
 5 </head>
 6 <body>
 7   <form action="RequestDemo2.jsp" method="post">
 8     用户名:<input type= "text" name="username"/><br>
 9     用户密码:<input type= "password" name="userpassword"/>
10     <input type="submit" value="提交">
11   </form>
12 </body>
13 </html>
View Code

 

RequestDemo2.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" import="java.util.*" %>
 2 <html>
 3 <head>
 4   <title>使用request对象获得所有的参数名称</title>
 5 </head>
 6 <body>
 7   <%-- 通过request对象的getParameterNames --%>  
 8   <% 
 9  Enumeration<String> e = request.getParameterNames();//获得所有的参数名称 10     while(e.hasMoreElements()){ //遍历Enumeration 11       String str = (String)e.nextElement(); //取出下一个元素值 12  out.println(str);//打印输出变量名称 13  } 14   %>
15 </body>
16 </html>
View Code

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM