Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in JSP

Status
Not open for further replies.

AlexR

Programmer
Feb 19, 2002
17
0
0
US
Below is a JSP that I got to work in Tomcat but when I call the page a second time I get an error: java.lang.ArrayIndexOutOfBoundsException, I have narrowed down the problem to the generateCombinations() method. I ran this same program as a java class from the compiler and it works fine, but when I write it out as a JSP it will only compile and run fine the first time and any time after that it will throw an error.

<HTML><HEAD>
<TITLE>Permutation JSP</TITLE>
</HEAD><BODY>
<%!
String letters = &quot;ABCDE&quot;;
String temp = &quot;&quot;;
int ltrsLen = letters.length();
String[] combo;
int c = 0;
%>
<%!
public void generateCombinations (String s, String slist, int maxc)
{
if (slist.length() == 0 || s.length() == maxc)
{
combo[c] = s;
c++;
}
for (int i = 0; i < slist.length(); i++)
{
String ts = s + slist.substring(i,(i+1));
String tlist = &quot;&quot;;
for (int j = 0; j < slist.length(); j++)
{
if (i != j)
{
tlist = tlist + slist.substring(j,(j+1));
}
}
generateCombinations(ts,tlist,maxc);
}
}
%>
<%
int tCount = 1;
for (int t = ltrsLen; t > 0; t--)
{
tCount = tCount * t;
}
combo = new String[tCount];
generateCombinations (temp,letters,ltrsLen);
%>
<B>All combinations of <%= letters %> </B><BR>
<%
for (int cm = 0; cm < combo.length; cm++)
{
out.println(combo[cm] + &quot; - &quot;);
}
%>
<BR><BR><BR><B>All combinations of A before D </B><BR>
<%
for (int cm = 0; cm < combo.length; cm++)
{
if (combo[cm].indexOf('A') < combo[cm].indexOf('D'))
{
out.println(combo[cm] + &quot; - &quot;);
}
}
%>
<BR><BR><BR><B>All combinations of A before C and C before E </B><BR>
<%
for (int cm = 0; cm < combo.length; cm++)
{
if (combo[cm].indexOf('A') < combo[cm].indexOf('C') &&
combo[cm].indexOf('C') < combo[cm].indexOf('E'))
{
out.println(combo[cm] + &quot; - &quot;);
}
}
%>
</BODY>
</HTML>
 
>> I have narrowed down the problem to the
>> generateCombinations() method

then

>> it will throw an error

The exception reports the exact line the error occured on. So why do you only have it narrowed down to an entire function?

-pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top