File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes calling same jsp on submit button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "calling same jsp on submit button" Watch "calling same jsp on submit button" New topic

calling same jsp on submit button

Diptee Bhakre

Joined: Apr 06, 2010
Posts: 2
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.* ,*"%>
<jsp:useBean id="bean" class="Processor" scope="session">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<form name="branch" target="_top" action="" method="get">
<input type="submit" name="submit" value="submit"/>
<%! ArrayList list = new ArrayList(); %>

for (int i=0;i<list.size(); i++)

out.println("List is" + list.getList(i));


Nd My bean class is as follows.
import java.util.*;

public class Processor
ArrayList allBranchList = new ArrayList();
public ArrayList getList()

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)
catch( Exception e)
return allBranchList;

public static void main(String args[])



Thanks in advance.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

The solution to many vexing problems like this is to structure your web apps properly. Step one of that effort is to remove all Java code from the JSPs and not use them as controllers.

Please read this article for information on properly structuring web apps.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: calling same jsp on submit button
It's not a secret anymore!