• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The value attribute in Reverse2Servlet

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gotcha
Cheers guys i the light has flicked back on
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic