How to read request parameters passed in URL using JSP?


The following URL will pass two values to HelloForm program using the GET method.

href="http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI" 

Below is the main.jsp JSP program to handle input given by web browser. We are going to use the getParameter() method which makes it very easy to access the passed information −

<html>
   <head>
      <title>Using GET Method to Read Form Data</title>
   </head>
   <body>
      <h1>Using GET Method to Read Form Data</h1>
      <ul>
         <li><p><b>First Name:</b>
            <%= request.getParameter("first_name")%>
            </p></li>
         <li><p><b>Last Name:</b>
            <%= request.getParameter("last_name")%>
            </p></li>
      </ul>
   </body>
</html>

Now type href="http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI" in your browser's Location:box. This will generate the following result −

Using GET Method to Read Form Data

  • First Name: ZARA

  • Last Name: ALI

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements