Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
How to use multiple declaration in jsp 
 

JSP provide two ways to declare variables or methods:

 

How to use multiple declaration in jsp

                         

JSP provide two ways to declare variables or methods:

1: Declare in scriptlet :- The scope of this kind of declaration is only in same block.

Example.  <% int number, count, flag ; %>

2: Declare in directive :- If we declare in directive, it is applicable in whole page.

Example.  <%! int number; %>          

In the jsp code given below, you will learn how to declare multiple variables and methods in jsp  that prints the sum of two numbers. Before running this java code create a new directory named "user" in the tomcat-6.0.16/webapps and WEB-INF directory in same directory.

 multi_declaration_jsp.jsp

<HTML>
    <HEAD>
        <TITLE>multiple declaration in jsp</TITLE>
    </HEAD>
    <BODY bgcolor="#6E6E6E">
<font size="+3" color="#F6CECE">Example of multiple declaration.</font>
	<!-- multiple declaration of variables and methods -->
	<%! int num1 = 10; %>
	<%! int num2 = 5; %> 
	<%! int add(){ 
		return num1+num2; }
	%>
	<%! int sub() {
         return num1-num2;
	}
	%>
	<br>
    <font size="+3" color="#E6E6E6">Sum : <%= add()%></font>
	<br>
    <font size="+3" color="#E6E6E6">Subtraction : <%= sub()%></font>
</body> 
</html>

Save this code as a .jsp file named "multi_declaration_jsp.jsp" in the directory Tomcat-6.0.16/webapps/user/ and you can run this jsp page with url http://localhost:8080/user/multi_declaration_jsp.jsp in address bar of the browser.

Download Source Code

                         

» View all related tutorials
Related Tags: java c string jsp ide class strings script object io objects method get char ip using sequence id declaration length

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.