File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Null Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Null Problem." Watch "Null Problem." New topic
Author

Null Problem.

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello Sirs and Ranchers ,

Today , i have a problem which i want to discuss with you'll. Off lately , My company has started given me some code files and that code files are actually written by someone who has already left the company and he did not document eveything. So all the variables or whatever beans , jsp and servlets , its sort of going bouncer over my head.. Its not that i do not know Web component architecture. I have alwayz worked with JSP and Servlets , Beans etc . However , seeing someone's coded files and then to understand them is very tough. Can someone of you , please guide me on how do i go about learning this code files.

Now , the problem. What actually has happened is , there is a combobox in which the user has an option to select the delivery options , The user selects the "Shipping Details" combobox and then submits. Though the user fills in all the details , When it comes to the Database , It is recorded as NULL , NULL , NULL , NULL. There are 8-9 fields related to the shipping details , in all of them this comes as NULL. And the main part which is being killing me is it sometimes does work like butter , nice ! But sometimes like NULL and Null. Does anyone have an idea what can be the problem behind this ?

I again reiterate , it works most of the times , but sometimes just comes as NULL. Also it does not throw any exceptions. How can i check this one ?

WOuld be great if a lot of people suggest on this.

Thanks in Advance.

Yogendra Joshi.

[Bear edit: explitives removed -- please control your language]
[ June 24, 2006: Message edited by: Bear Bibeault ]

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
A solution to your problem would be to do form validation using javascript before you post the data to a servlet or another resource wherever its going later.

Search online on how to do form validation using javascript. Also one suggesstion is that don't ask a question that is so long. People who post here are pretty busy like me and you, so ask any question directly.

hope this helps.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Originally posted by vishwanath nadimpally:
A solution to your problem would be to do form validation using javascript before you post the data to a servlet or another resource wherever its going later.


Server-side code should never rely upon any client-side validation taking place, It's too easy for users to disable JavaScript and it's to easy to spoof submissions.

Also one suggesstion is that don't ask a question that is so long.


Questions should be as long as they need to be. Nothing is more annoying than when someone posts a question that doesn't have enough information to analyze the problem.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Logging (even if only with System.out.println) is your best friend when working through other people's code.

Add lines throughout the code to tell you what the value of all of your variables are at different locations in your code. Then watch your logs as you hit the app. If you're on a Unix box, the tail program will allow you to watch the logs as they are being written, in real time. I believe there is a windows version of tail.

Real logging packages like Log4j allow you to keep the debugging lines in your code but turn the logging levels up or down at run time.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello Vishwanath , Ben and Bear ,

Thanks for replying and letting me know of our realy best friend , System.out.println :-) But the problem is still in question , Why does the same code work perfectly most of the time and also the Database gets filled in correctly while sometimes it records NULL.

This is the start of my Java Career and if this is not resolved , may be i would be revoked the rights to perform Java programming ! :-( Well thats too far away coz i am a member of this great site and reader of great books with great Authors like K & B and Hanumant Deshmukh.

Then too , any help would be highly appreciated. Thanks again.

Yogendra Joshi.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The reason I gave you that advice is that's what I would do to figure out what's going on. There is no way for someone on this list to determine the nature of you problem. Something is different between the hits that write data to the database and the ones that write nulls. You'll have to figure out what that difference is.

A good part of your career is going to be spent figuring out forgein code; written by someone else or by you a long time ago (often the two aren't much different in practice).
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
However , seeing someone's coded files and then to understand them is very tough. Can someone of you , please guide me on how do i go about learning this code files.

First analyze the product from an user's perspective. ie., forget about the code. take a piece of paper and write down what you do as an user (Enter Username and password and press login, The Welcome Page is displayed with menus, Click on the maintenance menu....)

Now start by looking at the code for login.jsp and try to understand how the developer had coded it. After that makes sense, move on to the menu page etc..

This approach has always worked for me


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Without looking at the code it is impossible to say why things come out null.
Welcome to the frustrating world of debugging code.

Are you reliably able to duplicate the error? Or does it just happen every once in a while?
Is there code that goes through and sets those values to null? When/why would it get called?
Maybe some error handling failed, and it went on to save anyway?
Maybe it could be a synchronization/threading problem. Is the page using <%! %> declarations, or servlet attributes which might create a synchronization problem?

Getting an idea of the data flows through the application is crucial to solving it.

Good luck,
evnafets
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
How about writing some test cases? It'd provide you the exact test-case that cause the failure.

P.S. Logging is your best bet in this case
[ June 26, 2006: Message edited by: Adeel Ansari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Problem.