• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tag, you're it.

 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on the third servlet assignment in the cattle drive, and after weeks of struggling to get something that works, I'm almost there.
I've got a jsp file that displays a form consisting of a text box and submit button. The text in the box gets reversed, as long as it's only 1 word long. If a phrase is entered, only the last word of the phrase is reversed and put back in the text box. I can't figure out what the problem is. I used a JSP expression as the value attribute for the text box. I know when I was using a variable as the value attribute in a straight servlet using println(), I had to do a '"+variable+"' thing to make it work. Is there some similar trick with JSP?
 
Jesus Angeles
Ranch Hand
Posts: 2069
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi carol

in which method do you do the reverse? would you mind posting that method code here?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for quoting problems in your HTML, particularly with your input tags. make sure that the entire string is begin returned as the submission parameter. If so, then it's probably a logic error in your reverse algorithm.
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to post code unless I have to, because it is a cattle drive assignment. So I'll have to be cryptic.
My JSP page has only HTML tags with one JSP tag, which I've placed where the value attribute string would normally go. Since I'm not using println() to print out the HTML code, I haven't had to use any quotes on the page. When I've tried using single or double quotes around the variable, the attribute isn't read properly and the servlet doesn't work.
I'm thinking that the entire phrase is being passed because the last word is diplaying in reverse. If the first word was the only one being passed along, then it would be the one getting reversed. Follow me so far?
I'm using much of the same coding logic I used for this assignment when it was just a servlet alone. If it worked then, shouldn't it work now?
It has to be that pesky value="I'm here to cause you to lose sleep" attribute. These single/double quotes messed me up before, and I think they're doing it again!
 
Jesus Angeles
Ranch Hand
Posts: 2069
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this calls for debugging line by line

when you have no debug tool, then println is helpful

heres one trap you can set

just println the string you received before reversing it

if it prints the whole sentence, then its cool, your method is getting correct input.

and then, println just before exiting the reverse method, you should see whole sentence reverse. if not, if you see only the last word reversed, then, the error is between those 2 printlns.

if the println shows correctly reversed sentence, then the error is in the process of returning the string to the client,..that is, in the jsp that will display the reversed
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesus. I will check out your suggestions and let you know what I find out!
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viewing source on the generated HTML page can often give an excellent idea of what is wrong.
It will at least let you see what is being generated.

My guess is that you have something like
<input type=text value=<%= reversedString >>
If you typed in "hello world"
Which would generate: value=dlrow olleh
but only put the word "dlrow" into the textbox.

putting quotes around the HTMl attributes would possibly solve it.
<input type="text" value="<%= reversedString%>">

reversedString would have to be escaped if it had any " characters in it so as not to interfere with the HTML. The <cut> tag does that nicely ;-)
[ September 25, 2005: Message edited by: Stefan Evans ]
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All it took was a set of single quotes around the tag. Funny thing is, that's the first thing I tried, but it didn't work the first time. Now I recall that I was having other issues with the code, and it probably wasn't working because of one of those other issues. Anyway, works now! Thanks for helping me with this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!