JSP Request

The request object is used to fetch the user's data from the browser and pass this data to the server. The working of JSP request object is similar to the servlet's HttpServletRequest interface object.

Example of JSP Request

In this example, request object fetches the form data.

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tutorial and Example</title>
</head>
<body>
<h3 align="center">
<form action="index.jsp">
Name :<input type="text" name="name"> <br>
Course:<select name="Course" style="width:230px">
<option value="JAVA">JAVA</option>
<option value="PHP">PHP</option>
<option value="Python">Python</option>
<option value="Other">Other</option>
</select> <br>
<input type="submit" value="submit">
</form>
</h3>
</body>
</html>

index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tutorial and Example</title>
</head>
<body>
<center>
<%
String str1=request.getParameter("name");
String str2=request.getParameter("Course");
%>
<h2>
<%="Welcome "+str1%> <br>
</h2>
<%="Your course : "+str2 %>
</center>
</body>
</html>
Output: