Request object in jsp

Satyapriyanayak
Posted by Satyapriyanayak under Others category on | Points: 40 | Views : 376
In this Code Snippets we will know about the use request object in jsp


Java server pages use request of the user with the help of request object. This is an object of javax.servlet.httpServletRequest.This object is available as the first parameter of _jspService () method present in the servlet generated behind the jsp. All methods of httpservletRequest can be used upon request object. The form tag needs to use name of the jsp file as the value of its action attribute.



Example : - Using request object to determine whether a number is even or odd.

<html>
<body bgcolor="pink">
<%
String str=request.getParameter("t1");
%>
<form>
<h2>Enter a Number<input type="text" name="t1"></h2>
<input type="submit" value="submit">
</form>
<%
if(str!=null)
{
int x=Integer.parseInt(str);
if(x %2==0)
{
%>
<h1>The Number <font color="red"><%= x %></font> is even </h1>
<%
}
else
{
%>
<h1>The Number <font color="red"><%= x %></font> is odd </h1>
<%
}
}
%>
</body>
</html>

Comments or Responses

Login to post response