• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we define multiple forward on single servlet?

 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am trying to do is defining one forward inside IF statement and one after that statement ended.
But it is not working. Please tell me why?
When I am defining only one forward after the IF statement it is working alright.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ronney singh wrote:But it is not working. Please tell me why?


Start by reading our FAQ documents at these links: ItDoesntWorkIsUseless, TellTheDetails.
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am expecting to happen is if variable value is 'e' then some code will run and forward it to "edit" action
If variable value is not 'e' then servlet should forward it to "failure" action
For better understanding code

This servlet is forwarding the page to "failure" action even when the String mode is 'e'.
when I have removed "forward=mapping.findForward("failure");" then error came that website has programming error or it is under maintenance.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yeah. If the mode is 'e' then eventually line 19 is executed. And right after that, line 22 is executed. What is the end result?

This is Java code you have posted there. It runs in a Java runtime environment. It's Java. Don't assume that just because you have a variable named "forward" that it will be treated differently than any other variable.
 
Krystian Gor
Ranch Hand
Posts: 30
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ever heard of else?
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have written last line-"forward=mapping.findForward("failure");"
in else but still when the value of mode is 'e' it is forwarding to failure action. Why it is so?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us, don't tell us. And be sure to use proper indentation in your code. It's really hard to see the conditional structures when your code is poorly written.
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, yeah. If the mode is 'e' then eventually line 19 is executed. And right after that, line 22 is executed. What is the end result?


But When I removed line 22 and value of mode is 'e' then why it is showing "website has programming error" because now the last value of forward must be 'edit'?
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code-
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If line 25 is executing, then mode isn't 'e'.

Why aren't you using logging statements or a debugger to debug this?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ronney singh wrote:why it is showing "website has programming error"


How should we know? We don't even know what the "it" is which showing that. (You didn't TellTheDetails.) At any rate let's assume that it's correct. Then the website (yours) has a programming error. Quite possibly that's because some code threw an exception, although that's just a guess. In which case it's quite likely that there is a log which will contain a stack trace of that exception; you should look for that.
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked the value of mode on jsp page where "failure" is forwarding by using scriptlet

It is showing that value of mode is 'e'.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means nothing. It's the value in the servlet that matters.

So:
  • Why aren't you using logging or a debugger to debug this?
  • Why do you have discredited scriptlets in your JSP? That's a really poor practice.
  •  
    Paul Clapham
    Sheriff
    Posts: 21322
    32
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bear Bibeault wrote:If line 25 is executing, then mode isn't 'e'.


    Actually the expression

    will always return false regardless of the value of the mode variable (except if it's null). It would be less confusing and more accurate to use this instead:
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65122
    91
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Doh! Missed the single quotes! Good catch!
     
    ronney singh
    Ranch Hand
    Posts: 40
    IBM DB2 Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks and Great catch sir
    I am Beginner in java I don't have any idea how to use logging so it would be great if anyone can provide me link how to use logging.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65122
    91
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    ronney singh
    Ranch Hand
    Posts: 40
    IBM DB2 Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you very much sir.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic