Home Tutorial Java Jsp Arraylist JSP Arraylist Index

 
 

Share on Google+Share on Google+
JSP Arraylist Index
Posted on: March 15, 2010 at 12:00 AM
Advertisement
In this current tutorial you will come to know about ArrayList implementation in JSP. ArrayList is a class and a member of Java Collection Framework.It is the resizable-array and permit all element including the null.

Description:

ArrayList is a class and a member of Java Collection Framework. It is the resizable-array and permit all element including the null. It is similar to Vector but it is unsynchronized. Iterator return the element from the list in proper sequence.

In this example there are two file index.jsp and postindex.jsp. The index.jsp file take the user input from three different textbox and value to the postindex.jsp, which take all values and placed into the ArrayList object. Through Iterator all the element of the list is shown in proper sequence.

Code for JSP Arraylist index.jsp & postindex.jsp:

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<form action="postIndex.jsp" method="POST">

<table border="1">

<tbody>

<tr>

<td>First Element</td>

<td><input type="text" name="arraylistvalue1" value=""></td>

</tr>

<tr>

<td>Second Element</td>

<td><input type="text" name="arraylistvalue2" value=""></td>

</tr>

<tr>

<td>Third Element</td>

<td><input type="text" name="arraylistvalue3" value=""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="submit"></td>

</tr>

</tbody>

</table>

</form>

</body>

</html>

postindex.jsp

<%@page import="java.util.*" contentType="text/html"

pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">]

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>

<body>

<%

String str1 = request.getParameter("arraylistvalue1");

%>

<%

String str2 = request.getParameter("arraylistvalue2");

%>

<%

String str3 = request.getParameter("arraylistvalue3");

%>

 

<%

ArrayList alist = new ArrayList();

alist.add(str1);

alist.add(str2);

alist.add(str3);

%>

<table border="1">

<thead>

<tr>

<th>Index</th>

<th>Values</th>

</tr>

</thead>

<%

Iterator iter = alist.iterator();

%>

<%!int x = 0;%>

<%

while (iter.hasNext()) {

%>

<tbody>

<tr>

<td><%=++x%></td>

<td><%=iter.next()%></td>

</tr>

<%

}

%>

</table>

</body>

</html>

Output:

 

 

Download this code
Advertisement

Related Tags for JSP Arraylist Index:


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 15, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com