Knowledgebase: Java/JSP Hosting Plans
Getting a Request Parameter in a JSP Page
Posted by Customer Service on 25 May 2005 12:34 AM
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 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:
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>!");
(609 vote(s))
Not helpful

Comments (0)