I am facing problem in my jsp.
I am calling same jsp called a.jsp when I click my submit button. I want to call getList() to call once when jsp is calling for first time and when submit is click , no need to call getList(). I am doing some opreation on arraylist provided by getList(). Could any body help me how I can achieved it? My jsp and java code is posted here. My code is as follows.
<%@page import="Processor"%>
<%@ page import="java.util.*, java.sql.* ,java.io.*"%>
<jsp:useBean id="bean" class="Processor" scope="session">
</jsp:useBean>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="branch" target="_top" action="" method="get">
<input type="submit" name="submit" value="submit"/>
</form>
<%! ArrayList list = new ArrayList(); %>
<%
if(!session.isNew())
{
list=bean.getList();
for (int i=0;i<list.size(); i++)
{
out.println("List is" + list.getList(i));
}
}
%>
</body>
</html>
Nd My bean class is as follows.
import java.io.*;
import java.util.*;
public class Processor
{
ArrayList allBranchList = new ArrayList();
public ArrayList getList()
{
try
{
String lineData = null;
File f = new File("C:/abc.txt");
FileReader fr = new FileReader(f);
BufferedReader bfr = new BufferedReader(fr);
while((lineData = bfr.readLine())!= null)
{
allBranchList.add(lineData);
}
}
catch( Exception e)
{
e.printStackTrace();
}
return allBranchList;
}
public static void main(String args[])
{
}
}
Thanks in advance.