• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple factorial program

 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am JSP beginner and I have developed a code to calculate factorial of numbers. But I am facing a problem.
I am getting error on this code . Can any one suggest me solution as well as what is the problem in this code ??
(I want to do full coding in a single JSP file.)








Error
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, you should not keep Java code in JSPs; that's a thoroughly outdated and obsolete way of creating web apps.

As to the problem at hand, when you access this JSP, n1 and n2 are not present, and so Integer.parseInt is trying to parse a null value. All that code should only be executed if n1 and n2 are present - after the form has been submitted.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if I want to code in single file ?? Can you please help me with the suggestions needed to run this code ?
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if I want to code in single file ??


Fortunately "if" can be used in the code snippets in JSP making possible the conditional executing of code!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if I want to code in single file?

It's just bad style. If you're just starting out you should not get into bad habits that will be hard to break later on. And break it you will have to, because a professional environment will not let you get away with scriptlets.

Can you please help me with the suggestions needed to run this code ?

Haven't I told you what the problem is? What do you think you have to do to fix it?
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:Fortunately "if" can be used in the code snippets in JSP making possible the conditional executing of code!


thank you, but I am already trying for a long time, also tried with IF, can you please help me further to complete so that I can unserstand ??
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you tried something you should tell us what that was. You must not pass a null value to Integer.parseInt, that's for sure. Alternatively, do proper exception handling with a try/catch block.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!