JSP Request implicit Object

The request object is type of HttpServletRequest.

which is available in javax.servlet.http.HttpServletRequest package.

For each request container create request object.

The request object provides methods to get form data, cookies, HTTP methods etc.

Methods to get form data.

syntax:

1
2
 
String username = req.getParameter("username");

i.e

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<head>
<title>Insert title here</title>
</head>
<body>
 
<h1>MyPage</h1>
 
<form action="/requestobject">
 
User name: <input type="text" name="user_name">
<input type="submit" value="Enter">
 
</form>
 
</body>
</html>

RequestObject.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@ page language="java" %>
<html>
<head>
<title>Insert title here</title>
</head>
 
<body>
<%
 
String user=request.getParameter("user_name");
 
%>
 
Hello <%=user %>
 
</body>
</html>

index.html


request

Enter username and Click on enter


2-enter-user-name

output:


3-output

Leave a Reply

Your email address will not be published. Required fields are marked *