Blog

Request object in JSP

Posted by Satyapriya Nayak Blogs | JSP Sep 17, 2011
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>

 

 

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.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.