*
The moose likes Cattle Drive and the fly likes Servlets 4a (different question) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Servlets 4a (different question)" Watch "Servlets 4a (different question)" New topic
Author

Servlets 4a (different question)

Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
i am having a problem with the DVD/VHS check boxes... if i check both boxes everything works fine, but if one (or both) of the boxes are left blank, the data does not seem to make it to the array.
i put some code in the AddaVideo servlet to print the input just so i could see what was happening. if i do not check one of the boxes, the output .html file is blank.
i am getting the "String" from the check boxes like the other parameters and then "casting" it to a boolean... is there a better way to do this? i am thinking there is and that is why i am having problems.
side note: the mystery file isn't necessarily a .java file, is it?


what?
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Glad to hear someone else has the same problem
I've been struggeling with the same problem for 2 hours , gave up and sent Marilyn the attempt with the bug in it , to see if I'm on the right track with my mystery file. Mine is a java file by the way.
I will look into it later again. Am busy with Servlet 4b now.
I'll let you know if I find the answer.
Good luck
[This message has been edited by Johannes de Jong (edited October 13, 2001).]
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
I've solved my problem !!
If the check box is not checked the default value is null.
Hope this helps Greg
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
What I did was used the ?: operator. Basically, if that parameter is null, you print one message in the field, if it isn't (meaning that the box is checked), you print something else in the field. Don't need to worry about casting or anything.
Hope that helps
Jason
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Wow, got that in there while I was typing in my response, nice work JdJ
That's why yer da man
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
wow, i did not expect a response to this until monday! thanks.
i guess i should have been more specific, though. if one or both of my boxes are not checked, none of the information gets passed to the array (or the debugging html page). i will try your ideas and see if that changes anything... if i do not cast, i can take out a step in my program, and that might be causing the problem
so, JdJ, you are trying to get back on the "active" list, huh? good to see you are back at it!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Greg Harris:
side note: the mystery file isn't necessarily a .java file, is it?

It is a .java file in the instructor's solution.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
thanks, Marilyn, i guess i can say what i was thinking now: i was trying to use a web.xml file to share objects...
i have been banging my head on the desk most of the day with this one, so i guess it is time to put it away and come back when my brain has regenerated some lost cells. oh, wait, the brain doesn't regenerate, does it?
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Yep Greg I'm back. Just mailed the corrected version off. Hope she excepts this correction
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Greg Harris:
[B]thanks, Marilyn, i guess i can say what i was thinking now: i was trying to use a web.xml file to share objects...

The xml assignments will eventually come after the JDBC assignments.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
okay, i think i have it now... what i need to know now is: what are we supposed to do about getting between the pages? are we supposed to include links at the bottom of the pages, or just make the user click the "back" button? the first page with both links is nice, but how do i get the user back to it?
----------
wow, my initial post really sounded stupid! you cannot "cast" from a string to a boolean!? what i meant was that i was using an "if" statement to set the value. i got an error telling me that i could NOT cast from a "string" to a "boolean"... so i guess that is where my mind was. i figured out what i was doing wrong, though. i was using the wrong method to test if the parameter contained a certain value.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
>okay, i think i have it now... what i need to know now is:
>what are we supposed to do about getting between the pages? are
>we supposed to include links at the bottom of the pages, or just
>make the user click the "back" button? the first page with both
>links is nice, but how do i get the user back to it?

For this assignment (Servlets-4a), it's not a big deal. You can use the "back" button if you want or links if you want or even buttons if you want.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Roedy Green's Java Glossary has a great conversion matrix for "basic types" in Java. See:
http://209.139.205.39/converttable.html

The usual URL is http://mindprod.com/, but the site was recently hacked and had to be moved to a different server. Until the DNS entry propagates, use the numeric IP address.
In your case, just look up "to boolean t from String g" for a nullsafe idiom for converting Strings to booleans. Since you know what's being passed in, I think you can use just "g" and not "g.trim()".
If you've never looked at the Java Glossary before, How to Write Unmaintainable Code is a fun place to start.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Sorry. Doesn't work. I forgot that addvideo.html uses "yes" and not "true" to indicate that the checkbox is checked.
You know, you can call methods on string literals:
int index = "yes".indexOf( 'e' ) ;
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
thanks, Michael... great link!
i figured there would be a way to cast a "true/false" string, but not the "yes/null" string. i wonder if this is Paul's sly way of torturing us? if i were to write the html form myslef, i think i would use a value of "true", but at least now i have a better understanding of the java specification (that is the point, right?).
it is amazing how simple the solution can be sometimes... it is also amazing how hard it can be to find that solution when you get started in the wrong direction! (hmmm, i see a chinese proverb in there somewhere)
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Greg I was reading the JSP Servlets section of Profesional Java Data just now and the author of that part of the book (it's a Wrox book with tons of writers) actually suggests that you test for null and not "yes", as people tend to use different values ie, "yes", "on" to indicate that the check box is clicked. If it is not null the check box was clicked.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
what a coincidence... that is what i changed in my program to make it work.
i was testing for yes and then ! yes, but it was not working. i guess because if it was null then the test was failing since there was not a "string" to test...
so, now i am testing for ! null and everything seems to work fine.
[This message has been edited by Greg Harris (edited October 14, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets 4a (different question)
 
Similar Threads
How to select a particular checkbox in a series
Total No. of answers to be given
Struts Validator - 3 textboxes to one error
Problem with double submit
JavaScript function on Input type dynamically generated