hi guys!I have seen many posts with redirecting from jsps,but my problem was quiet a different one.Actually I want to write 3 programs for validating user for his two input numbers.I wrote 3 programs.Index.html,Index.jsp,Error.jsp.
my Index.html is:
<form action="Index.jsp" method="post"> //I want to go to Index.jsp on clicking submit button
Enter 1st No : <input type="text" name="t1">
Enter 2nd No : <input type="text" name="t2">
<input type="submit" value="submit">
</form>
My Index.jsp is:
<%@page errorPage="Error.jsp"%>
<%!
int a;int b;int c;%>
<% a=Integer.parseInt(request.getParameter("t1"));
b=Integer.parseInt(request.getParameter("t2"));
if ((a>b)||(a==b))
{
c=a/b;
out.println("Division Result="+c);
}
else
{
out.println("Divide greater number by smaller number.");
out.println("<br>Try again");
//response.sendRedirect("
http://localhost:8080/jsp4/Index.html");
}
%>
My Error.jsp is:<%@page isErrorPage="true"%>
Runtime exception:
Possible cases may be:
1.You have divided an Integer/Non-Integer by 0.
2.You have divided 0 by 0.
3.You have divided an Integer by a Non-Integer.
4.You have divided a Non-Integer by an Integer.
5.You have divided a Non-Integer by a Non-Integer.
6.You didn't give any of the two Integer values or both.
Please check again...
.
//<%
//response.sendRedirect("http://localhost:8080/jsp4/Index.html");
//%>
I want to redirect form my Index.jsp to Index.html if a<b,but if I include sendRedirect() in scriptlet,it doesnot execute my else part out.println("Divide greater number by smaller number.");out.println("<br>Try again");.it directly redirects to html page.similarly I want to redirect from my Error.jsp to Index.html,but again it directly redirects to html page without printing Possible cases may be....I want to print else part printing statements and html printing statements then only it should redirect.tried using Thread.sleep()but it justs wait and redirect.tried using <%pageContext.forward("page1.jsp");%>,but again same problem!Please help me!