Home Jsp Simple-jsp-example Creating a Local Variable in JSP
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Creating a Local Variable in JSP

Advertisement
In jsp when we have to create a method or variable we usually declare it inside the declaration tag. If we declare it inside the declaration directive then then the scope of the variables will be applicable in the whole page. This works like a instance va

Creating a Local Variable in JSP

    

In jsp when we have to create a method or variable we usually declare it inside the declaration tag. If we declare it inside the declaration directive then then the scope of the variables will be applicable in the whole page. This works like a instance variable. 

Now consider a situation where we have to declare a variable as local, then we should declare the methods and variables in tag except the declaration directive. In this example we are declaring a variable in the scriptlet directive, so the scope of the variable remains upto the scriptlet directive itself. To print the variable on the browse we will use the out implicit object. 

 

 

<HTML>
  <HEAD>
    <TITLE>Creating a Variable in Jsp</TITLE>
  </HEAD>
  <BODY>
  
    <H1>Creating a Variable in jsp</H1>
    <%
	 int weeks;
	 weeks = 7;
	 out.println("Days of the weeks = " + weeks);
	 %>
	 <br>
	 <%
	 int months;
	 months = 12;
	 out.println("Number of months = "+ months);
	 %>
  </BODY>
</HTML>

Output of the Program:

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Related Tutorials

Ask Questions?    Discuss: Creating a Local Variable in JSP  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com