Blog

Request object in JSP

Sep 17, 2011 Blogs | JSP
In this blog we will know about the use request object in JSP.

In this blog 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>

 

 

Satyapriya Nayak

Satyapriya Nayak is a software developer from Bhubaneswar, India. He holds a Bachelor's degree in Electronics and telecommunication and is an active member of C# Corner. 

  • 7rank
  • 2M readers
  • 2times
COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs