• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

calling same jsp on submit button

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic