aspose file tools*
The moose likes Cattle Drive and the fly likes The value attribute in Reverse2Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "The value attribute in Reverse2Servlet" Watch "The value attribute in Reverse2Servlet" New topic
Author

The value attribute in Reverse2Servlet

Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Hi, i am struggling with one element of servlets-3. I have my servlet making my HTML form fine and i can enter a word into my textfield and received it reversed in my textfield when i press submit as is supposed to happen, and then happily press submit and see it reverse each time as it should...
My problem is when i enter more than one word in the textfield, i can out.println the whole string and can reverse the whole string in out.println line outside the textfield but when i go to put it in my textfield in the value tag it only puts in and revereses the last word, not the whole string.
e.g. i enter "the tick says spooooon!" and press submit, a normal out.println shows that string in reverse but in the textfield it only shows "!nooooops" and not the other words.
Any advice as to where i am going wrong its driving me mad and possibly to drink
Thanks
Sam


Sam Tilley SCJP, SCWCD
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
Almost seems like the "reverse" method is working from the end of the string and stopping when it finds the first space ... except you are getting both quotes. (Hmmm...) Did you write your own reverse method or are you using a method supplied by an existing class?
I am using a method supplied by an existing class in the javaranch libraries, and have not encountered this problem.
Another place you may want to look is in the HTML that you are generating for the value attribute. Would your HTML generate something like this
value="two words"
or this
value=two words
(The first example is what you want, not the second.)
These are just some off-the-cuff ideas, but I hope they help you. Sometimes it's really hard to tell what's going on without seeing the code, but as you know, we can't post that!
[ June 13, 2002: Message edited by: Louise Haydu ]
Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
I was just using the standard StringBuffer reverse method but also tried it using a class from the javaranch libraries but to the same effect. The strange thing is that when it prints to a out.println statement after i have pressed submit it reverses all the words fine but its only when i try to put it in the value attribute of the form that it takes just the last word.
V.strange but maybe i will have another bash at it tonight when i get a chance, i might of (make that have..) missed something somewhere
Cheers
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
OK, so your reverse method is working fine. So the problem has to be with how you are creating the HTML for the value attribute.
The browser will stop reading a value whenever it encounters white space (in this case an actual space character), unless that white space is contained within quotes.
If you want to see the HTML that you created,
you can view the HTML by selecting View/Page Source (Netscape) or View/Source(Internet Explorer).
[ June 13, 2002: Message edited by: Louise Haydu ]
[ June 13, 2002: Message edited by: Louise Haydu ]
Josue Cedeno
Ranch Hand

Joined: Feb 06, 2001
Posts: 71
Finally a thread that I know something about and you guys are all done. Louise is right. Be aware of your quotation marks.
I hope this doesn't totally give it away (where's the fun in that anyway)
Sam Tilley
Ranch Hand

Joined: Dec 05, 2001
Posts: 160
Gotcha
Cheers guys i the light has flicked back on
 
jQuery in Action, 2nd edition
 
subject: The value attribute in Reverse2Servlet