This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes redirecting from jsp without ignoring html statements 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 "redirecting from jsp without ignoring html statements" Watch "redirecting from jsp without ignoring html statements" New topic
Author

redirecting from jsp without ignoring html statements

raghavendra raghu
Greenhorn

Joined: Sep 01, 2012
Posts: 16
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!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

Hi Raghavendra. Welcome to the Ranch!

You can't produce output and redirect the browser at the same time. You either send content to the browser for it to display, or tell it to go somewhere else. But you can only send one response, so it doesn't make sense to try and do both. You're going to have to come up with a different solution to what you're trying to achieve.
raghavendra raghu
Greenhorn

Joined: Sep 01, 2012
Posts: 16
Matthew Brown wrote:Hi Raghavendra. Welcome to the Ranch!

You can't produce output and redirect the browser at the same time. You either send content to the browser for it to display, or tell it to go somewhere else. But you can only send one response, so it doesn't make sense to try and do both. You're going to have to come up with a different solution to what you're trying to achieve.


Nice to see an answer.I expected that actually.but is there any technology/method() to send 2 responses to server,i dont know if this is possible in jfs or other technologies.
thank you. Mathew:)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

raghavendra raghu wrote:but is there any technology/method() to send 2 responses to server

response to server? I think another request on response?
raghavendra raghu
Greenhorn

Joined: Sep 01, 2012
Posts: 16
Seetharaman Venkatasamy wrote:[
response to server? I think another request on response?


sorry Venkataswamy but I dont understand u.Iam a beginner in web technologies.please elaborate a way in which I can execute my html as well as sendresponse() method and also the code in my else part and sendResponse().could you tell me how another request on response should be done?There is so much fun in learning these things
raghavendra raghu
Greenhorn

Joined: Sep 01, 2012
Posts: 16
raghavendra raghu wrote:
Seetharaman Venkatasamy wrote:[
response to server? I think another request on response?


sorry for my wording.I actually intended to say is there any method or technology to make server execute my 2 requests simultaneously.refer my first post.Thanks.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Sorry just i posted previous post to mention terminology is important .... because still I struggle with that :)
raghavendra raghu
Greenhorn

Joined: Sep 01, 2012
Posts: 16
Seetharaman Venkatasamy wrote:Sorry just i posted previous post to mention terminology is important .... because still I struggle with that :)


haha.I think You get me now:)please post your response...people may think that Iam creating spam !!
 
wood burning stoves
 
subject: redirecting from jsp without ignoring html statements
 
Similar Threads
MultiDimenaional Array sort
response.sendRedirect help needed
HTTP method GET is not supported by this URL
<jsp:forward ...> not acting the way it should.
JSP attendance management project error