JAVA-JSP内置对象之request获得参数的参数值(一个值)

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

获得参数的参数值(一个值)


RequestForm3.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
 2 <html>
 3 <head>
 4   <title>表单</title>
 5 </head>
 6 <body>
 7   <form action="RequestDemo3.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

RequestDemo3.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       String strRequest = request.getParameter(str); //取得相应参数的参数值
13       out.println(str+"参数值为:"+strRequest+"<br>");//打印输出参数名称和参数值
14     }
15   %>
16 </body>
17 </html>
View Code
原文地址:https://www.cnblogs.com/FKdelphi/p/7669963.html