wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "calling same jsp on submit button" Watch "calling same jsp on submit button" New topic
Author

calling same jsp on submit button

Diptee Bhakre
Greenhorn

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.* ,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.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
wood burning stoves
 
subject: calling same jsp on submit button
 
Similar Threads
Problem in Uploading files other than text files
need help on jsp and xml
newbie question about servlets calling methods
tomcat crashes when counting lines in a text file
help on jsp and xml