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>
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>
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我

