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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Passing Arrays In Jsp Methods 
 

Array is a collection of similar data type. It is one of the simplest data structures. Arrays holds equally sized data elements generally of the similar data type. In an array the index starts from 0.

 

Passing Arrays In Jsp Methods

                          

Array is a collection of similar data type. It is one of  the simplest data structures. Arrays holds equally sized data elements generally of the similar data type. In an array the index starts from 0. Some arrays can be multidimensional. One and two- dimensional arrays are most commonly used arrays in java. JSP is a technology which enables us to mix html static component with the dynamically generated contents from servlets. In this jsp example we are going to make a program on Arrays. In this example we will mix  the html content i.e. static in nature, when this static content mix with the dynamic contents of jsp by using directive the page will become dynamic. 

In this example of  jsp for passing arrays in Jsp methods, first make a method named Addition(int[] a) of type void which will take an array of type int as its input, it will add the array elements by 2. This method is declared inside the declaration directive. Anything which will declared inside the declaration directive i.e. <%! ----------%> its scope will be applicable in the whole class. Now declare an array of type int inside the scriptlet directive and pass a value in the array.  The logic of the program is written inside the scriptlet directive. This directive is executed each time whenever the request comes for this  jsp page. This tag will be written inside a _jspservice() of HttpJspPage class when the jsp is translated into servlet. Now call the method Addition() inside the scriptlet directive so that the method can be executed and the result will be displayed to the user. To display the output call the implicit object out, which is responsible for displaying the content to the browser. At last save this page as Passing-Arrays-Methods.jsp.

Code of the program is given below:

<HTML>
  <HEAD>
    <TITLE>Passing Arrays In Jsp Methods</TITLE>
  </HEAD>
<BODY>
<table border="1" cellpadding="0" cellspacing="0" width="60%" align="center">
    <tr><td>
	<font  size="6" color ="#000080">Passing Arrays In Jsp Methods</font><br>
    <%!
    void Addition(int [] a)
    {
        for (int i = 0; i < a.length;i++) {
            a[ i ] += 2;
        }
    }
    %>
</td></tr>
<tr><td>
    <%
        int array[] = {2, 4 , 3, 6, 8};
        out.println("Before the call to Addition...<BR>");
        for (int i = 0; i < array.length; i++) {
            out.println("array[" + i + "] = " + array[i] + "<BR>");
        }
        Addition(array);
        out.println("After the call to Addition...<BR>");
        for (int i = 0; i < array.length; i++) {
            out.println("array[" + i + "] = " +
                array[i] + "<BR>");
        }
    %></td>
	</tr>
	</table>
  </BODY>
</HTML>

The output of the program is given below:

Download this example.
 

                          

» View all related tutorials
Related Tags: c math ide data div vi value number ddl id set element elements average mount to e ics in cs

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 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

I feel that starting java method name with capital letter is not the normal coding standard, although compiler does allow it. How do others feel about it ?

Posted by kuki on Friday, 05.2.08 @ 03:09am | #58334

If possible give more examples so that we can come up with clear idea.

Posted by vinoth on Monday, 02.12.07 @ 10:47am | #7496

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
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.