hi, i have a HTML form which has some text fields in it..the user can enter some or all of the fields and submit it..depending on the values entered..a search has to be made from the database...i captured the non-entered values in another jsp page using String name = getParameter("<field_name>") i'm getting an empty string into name. now need to use the variable name in the SQL statement in the JSP page as follows... "SELECT * FROM <table_name> WHERE SHEET_NAME = '" +name +"' or '"+name+"' IS NULL AND so on..."; but as name is empty... the condition for checking null is failing... can we set default vaues for the variables used so that when nothing is selected, the variable has a null value... can someone help me solve the problem...plz treat this as urgent thanks --sumana
Ok: 1o) Are you expecting an empty value in your name value? String name = request.getParameter("name") if you use this piece of code and your form with the name input field was empty, you should be getting null. maybe I didn't understand your problem.
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Sumana, I believe what may be happening is that in your HTML form you have something like: <input type="text" name="name" value=""> Therefore what will happen is when you submit the form the value for name will be set to an emptry String as specified by the form. What you can try is to remove the value="" from the form and then if nothing is entered name will be NULL. The query will still not work as in your SQL you will end uo with: OR NULL IS NULL and I am not sure if that is valid to do. hth
The secret to creativity is knowing how to hide your sources.
Joined: Sep 02, 2003
Originally posted by sumana ar: i think i'm getting an empty string bcz when i use the form action as get..the url is appended something like this... URL?name=&id=20 so now do u think i'm getting a null into the name variable..
Even if you use POST also same thing will happen. I think therez no way send null value from form to the jsp. Even if you send NULL, it will be sent as the string null rather than null value.
Joined: Aug 06, 2003
thanks for all those sugessions... actually i havn't given any value attribute to the text field and so an empty string is passed when nothing is selected. the problem is solved and anyways thanks for the help sumana