i have an index.jsp page when a customer clicks on a buy button i call additem.jsp passing the isbn code from url.At additem.jsp i take the isbn and find from my database the other columns i need.this is the additem.jsp code...
1) Use UBB code tags when posting code. It will preserve the formatting.
2) Never put Java code in a JSP. Factor it out into beans, or better yet, use a Model 2 controller pattern for your apps.
3) Don't eat the exception. By catching the exception and discarding it, you have lost any information on the nature of the error. Let the excpetion propogate outward so you will receive a stack trace that should give you the details about the error.
actually it said null pointer exception and i think it is because it doesnt put anything in shoppingCart!! its easier for me to understand creating my shopping cart this way..im a begginer so im trying..
my question is why not use the approach i have just posted..if it worked properly too!!!its a school project and finished about everything without the cart,checkout problem..and im stuck..any help will be more than welcome.now it doesnt print anything about an error.it just stays at additem.jsp doing nothing.
Originally posted by Aris Doxakis: my question is why not use the approach i have just posted..if it worked properly too!!!its a school project and finished about everything without the cart,checkout problem..and im stuck..any help will be more than welcome.now it doesnt print anything about an error.it just stays at additem.jsp doing nothing.
You've just given us one good reason for not using this approach. If you factor all of your database handling code back to a JavaBean, you can test it from the command line to make sure it's working before you start writing the web related or view related code. When, if you're using this approach, something does go wrong, it's usually a lot faster and easier to track it down.
Have you looked in your conatiner's logs to see if any errors are being reported there? [ January 10, 2006: Message edited by: Ben Souther ]
So you are telling me to call a servlet to do the job insted of calling additem.jsp,that i am doing?Please forgive me but my approach seems a little more easy,not that i am saying it is right,but for me,im a beggine:>,it seems easy.Actually though it doesnt work.Did you find any mistakes in my code?
It's difficult to read all that logic within JSP. That's why you have been adviced to refactor all the DB processing logic to a bean/servlet. Also, that will allow you to test that piece of code outside of the browser.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Originally posted by Aris Doxakis: but for me,im a beggine:>,it seems easy.
At the risk of poking a dead horse with a stick, you've been trying to fix this problem for how long now? Does it seem easy to you?
The point of well-factored code is that it is much easier to understand (therefore eassier to find bugs by inspection), and as Bosun pointed out, much easier to test.
Poorly structured code may seem easier to write, but you're finding out that it's a lot harder to get running correctly. So while it may seem like a waste of time learning how to properly structure your programs up front, you more than make up for it by not having to spend hours and hours chasing frustrating problems.
Claiming that you are a beginner is no excuse for shoddy code practices. In fact, as a beginner is the perfect time to learn and employ accepted best practices and patterns.