Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
JSP
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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. 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.
 

                          

Facing Programming Problem?
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

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.