This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Pipeline as Code and have Mohamed Labouardy on-line!
See this thread for details.
Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

redirecting from jsp without ignoring html statements

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

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:)
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

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

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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry just i posted previous post to mention terminology is important .... because still I struggle with that :)
 
raghavendra raghu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 !!
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic