java类库详细讲解
源代码在线查看: getparam.html
Getting a Request Parameter in a JSP Page
(Java Developers Almanac Example)
BODY CODE {font-family: Courier, Monospace; font-size: 11pt} TABLE, BODY {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} PRE {font-family: Courier, Monospace; font-size: 10pt} H3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt} A.eglink {text-decoration: none} A:hover.eglink {text-decoration: underline} -->
The Java Developers Almanac 1.4
Order this book from Amazon.
Home
>
List of Packages
>
javax.servlet.jsp
[18 examples]
>
Java Server Pages Input
[4 examples]
e1052.
Getting a Request Parameter in a JSP Page
In a GET request, the request parameters are taken from the query
string (the data following the question mark on the URL). For
example, the URL http://hostname.com?p1=v1&p2=v2 contains two
request parameters - p1 and p2. In a POST request, the
request parameters are taken from both query string and the posted
data which is encoded in the body of the request.
This example demonstrates how to include the value of a request
parameter in the generated output:
Hello <b><%= request.getParameter("name") %></b>!
If the page was accessed with the URL:
http://hostname.com/mywebapp/mypage.jsp?name=John+Smith
the resulting output would be:
Hello <b>John Smith</b>!
If name is not specified on the query string, the output would be:
Hello <b>null</b>!
This example uses the value of a query parameter in a scriptlet:
<%
if (request.getParameter("name") == null) {
out.println("Please enter your name.");
} else {
out.println("Hello <b>"+request.getParameter(i)+"</b>!");
}
%>
See also e1065 Getting a Request Parameter Using JSTL in a JSP Page.
Related Examples
e1053.
Including a File in a JSP Page
e1054.
Passing Parameters to Another JSP Page
e1055.
Using a Bean in a JSP Page
See also:
Java Server Pages
Java Server Pages Headers
Java Server Pages Output
© 2002 Addison-Wesley.