aspose file tools*
The moose likes JSP and the fly likes what's wrong with my code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "what Watch "what New topic
Author

what's wrong with my code?

dhuha al khoiri
Greenhorn

Joined: Apr 17, 2012
Posts: 24

I got an error like this,what does it mean??

Syed Muhammad Nayyar Mustafa
Greenhorn

Joined: May 02, 2012
Posts: 11

From what I understand, you've tried to convert a string variable with a value undefined for the numerical type you were converting to.
Use a try catch block to identify which block is throwing this exception and also print relevant strings to manually check their format.
The file in question is the one for dodepo and the exception is thrown at line 89 because of null argument to the call of Integer.parseInt.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

My guess is you're trying to parse a parameter to an int, but that parameter isn't set; getParameter returns null which is what you are trying to parse here (just check the exception message).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
dhuha al khoiri
Greenhorn

Joined: Apr 17, 2012
Posts: 24
this is my code



and this is the error said from tomcat :



btw,for hasil is mean result,its result but in indonesia language

so,where's part of my code,that have to add a code try and catch(exception)??
and tell me if my code have an error,or wrong code in this code,where's part of my code have an error and help me to fix it??

please help me,thanks,God Bless You All
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Before you continue, you should not be doing any java code in the jsp. That should all be done in a servlet. jsp should only be for viewing results / interacting with user.

your problem though, is that you should check that depo and lastdepo are not null before you try parseInt() on them.
Isuru Jay
Greenhorn

Joined: May 09, 2012
Posts: 7

Yes. you must check it is not null before you pass that value to that kind of operation. And are you sure you are passing a number through the request. so better to add a catch block as follow.

try{
idepo = Integer.parseInt(depo);
ilastdepo = Integer.parseInt(lastdepo);
}catch(Exception e){
}
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
String lastdepo = (String)session.getAttribute("sesiDepo");


Are you setting sesiDepo in session anywhere? All other fields are requet parameter.
Syed Muhammad Nayyar Mustafa
Greenhorn

Joined: May 02, 2012
Posts: 11

dhuha al khoiri wrote:this is my code



and this is the error said from tomcat :



btw,for hasil is mean result,its result but in indonesia language

so,where's part of my code,that have to add a code try and catch(exception)??
and tell me if my code have an error,or wrong code in this code,where's part of my code have an error and help me to fix it??

please help me,thanks,God Bless You All



Where are you setting value of sesiDepo ?
Is it in a block of code that will always run or does it depend on a condition to be satisfied ?
dhuha al khoiri
Greenhorn

Joined: Apr 17, 2012
Posts: 24

i was set SesiDepo value just in this file of dodepo.jsp ,and it depend on a condition to be satisfied,if the member success to deposit their money
they will have a deposit and they can buy some product, and if they already bought a product, member's money will accumulate from how much deposit money that their deposit minus(-) with product that their bought

so,i need SesiDepo,to know how much money that left in their deposit,and if their money left 0 or less than product's price,they have to deposit again


and i have an error in code dodepo.jsp, so money that member try to deposit,returns an error, they can't deposit money to buy product

i hope all of you understand what i mean,and i said


and after, i'm adding code


the error was gone,but it can't solve the problem,because member's money is still 0,and it stop just right there, not like the condition that i want

the condition that i want, member can deposit their's money,and show how much deposit money that they already deposit, and returns a success words,like:

"your deposit success"

please help me,God Bless You All
dhuha al khoiri
Greenhorn

Joined: Apr 17, 2012
Posts: 24

or just help me give some advice,or try to fix all of my code to fulfill my condition:

so,member can deposit their's money, and it returns success, so deposit money is'nt null anymore, and they can buy product

and after bought a product, money that left, members can see and know,so they can choose,whether to deposit again or not,if their's money left less than product's price


thanks
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

dhuha al khoiri wrote:
i was set SesiDepo value just in this file of dodepo.jsp ,and it depend on a condition to be satisfied,if the member success to deposit their money
they will have a deposit and they can buy some product, and if they already bought a product, member's money will accumulate from how much deposit money that their deposit minus(-) with product that their bought

so,i need SesiDepo,to know how much money that left in their deposit,and if their money left 0 or less than product's price,they have to deposit again


and i have an error in code dodepo.jsp, so money that member try to deposit,returns an error, they can't deposit money to buy product

i hope all of you understand what i mean,and i said


You have not shown the code where you set SesiDepo, but a session variable set in a jsp will not be available until the next trip back to the server.
The problems you are having are one of many reasons you should not be doing ANY of this work in a .jsp You need to throw away what you have done in the jsp and do it on a servlet instead.
The way you are doing this was accepted to be wrong 10 years ago and developing new code using this pattern SHOULD NOT BE .

I'm very concerned that Bear Bibeault is going to come and see this and the fact that we helped someone implement this pattern. Then there will be hell to pay.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Here's Bear!

Java code in a JSP?

Tim is absolutely correct. using scriptlets in a JSP is a practice that has been discredited for a decade now. DO you not think that it's time to catch up?

And even 10 years ago, any Java code in a JSP should have been for display purposes only -- not for processing. Even back then, everyone knew better than to mix non-view code into a JSP.

The time to be writing JSP pages as if it were still 2001 is long passed.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Syed Muhammad Nayyar Mustafa
Greenhorn

Joined: May 02, 2012
Posts: 11

dhuha al khoiri wrote:

this is my code,correct me if i am wrong,so i made index.jsp code,and dologin.jsp code,and i combine it like that,is that true?? thanks...



I found it on another thread by you
Is this the dodepo.jsp file you mentioned ?? because

whats the if clause that pairs with else clause at line 44 (here 01) ??


Is it missing from code as there is a place for it at line 24 (here 05) before the { , pointed to by ==>
I am asking about it because the if clause seemingly missing from here decides whether this block is entered or not (as seems to be the case here I think)

And I agree with suggestions made by previous posters about moving your business logic to servlets and just focus on presentation of results while making the jsp
If you have time, re-implement this web app based on advice made by previous posters
My advice will be to also explore javabeans for use in jsp
dhuha al khoiri
Greenhorn

Joined: Apr 17, 2012
Posts: 24

thanks for all of you,for your advice and for your kindness to helping me out from this problem
May God Bless You All...

i will do all of your advice,and correct my code,according to your advices...

and for file that you take Syed Muhammad Nayyar Mustafa is dologin.jsp, not dodepo.jsp

that file to make user can login,and know how many user that online..

thanks..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's wrong with my code?
 
Similar Threads
SQL Exception :general error
Unable to compile class for JSP
Variables from classes
NEWBIE question on created test client in Eclipse
forEach not working