在GET请求中,请求参数取自查询字符串(URL上问号后面的数据)。例如,URL http://hostname.com?p1=v1&p2=v2包含两个请求参数--p1和p2。在POST请求中,请求参数既取自查询字符串,也取自编码在请求正文中的发布数据。
此示例演示如何在生成的输出中包括请求参数的值:
Hello <b><%= request.getParameter("name") %></b>!如果使用URL访问页面:
http://hostname.com/mywebapp/mypage.jsp?name=John+Smith
结果输出将是:
Hello <b>John Smith</b>!
如果未在查询字符串上指定名称,则输出为:
Hello <b>null</b>!
本示例在脚本中使用查询参数的值:
<% if (request.getParameter("name") == null) { out.println("Please enter your name."); } else { out.println("Hello <b>"+request. getParameter("name")+"</b>!"); }%>


