• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Cannot forward after response has been committed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im kind of new to servlets. i have a servlet which accepts data from a HTML form. Basically 2 numbers, according to the option chosen, their addition,multiply etc. User enters the answer, servlet checks whether it was correct or not. If wrong, shows solution.
processRequest() is the function which is called by doPost. It calls processAnswer() which basically does the forwarding of the page according to the answer.
Heres processRequest

WHICH CALLS processAnswer()

Really need help here..I tried adding a "return" in processRequest, didnt help.
 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello and welcome to java ranch.

I am sorry, did not get your problem..
If "Cannot forward after response has been committed" is the problem then always remember that you can not forward the servlet/jsp to another one of a kind after you have committed the response to the client!! Remember that always, forward before you commit.

Hope this helps..
 
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

Originally posted by Udayaditya Barua:




processAnswer(answer, opt, number1, number2, request, response);

why you put after catch ?...i guess first it enters catch and forward to some page agin it calls processAnswer and init once agin you are trying to forward .... instead you put your processAnswer(answer, opt, number1, number2, request, response); inside try block
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Do remember that in switch case once a condition is met in a case all the subsequent case blocks get executed ,hence the error .To make it work find
an alternative to switch case approach.Try using if ...else I think it might
work out
[ December 06, 2008: Message edited by: Abhijit Rai ]
 
Udayaditya Barua
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@shekhar
thanks

Ok, sry for the delay.. Managed to solve the problem after a lot of searching... Had to write a 'return' after the forward command..
About the switch case executing every statement, doesnt writing a "break" solve that?..Just asking..
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes of course. You know the fundamentals of switch case statement.....
By writing break you tell the program to come out after the case has matched....
Otherwise once a case is matched and break is not used then all the subsequent cases too are evaluated.... Hope this helps.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic