Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

errorPage is not calling

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<body bgcolor=#87FFFF>
<form name="f1" action="test1.jsp">
<table>
<tr>
<td>Enter script number</td>
<td><input type=text name="script"></td>
</tr>

<tr>
<td><input type=submit value="OK"</td>
</tr>
</table>
</form>
</body>
</html>
Dear sir above is my html code now see followiing is my jsp code

<%@ page language="java"%>
<%@ page errorPage="errorpage.jsp"%>
<%
String[] str={"Arun","Kumar","maalik"};
String str1=request.getParameter("script");
int n=Integer.parseInt(str1.trim());
out.println(str[n]);
%>

and finally this is my errorpagecode

<%@ page isErrorPage="true"%>

<%=exception.getClass()%>
<%=exception.getMessage()%>

now when i am passing subscript as 0,1,2 it is working fine but when i am passing subscript as 5 or 6 any number it is not calling errorpage server is not connecting with error page all though i am deploying these 3 files in same contextroot why sir why

with regard

Arun kumar maalik
 
Shashi Kant
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

You are printng by using the statement -->

out.println(str[n]);

and while defineing the String str array object you have created it with initial 3 string parametes. So length of str object is 3, so you can access only three items in that object i.e. 0,1,2 index only.
So when you are passing the value greater then 2 this will definitely give you the error that Array Index Out of bounds.
So try that with increasing the size of string array.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic