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