My code for the servlet in Assignment: Servlets-3 Reverse2Servlet seems to be working except when a single quote gets put into the text box and submitted. When that happens the text that gets reversed and sent back is whatever is after the single quote and I am not sure how or whether I need to correct for this situation. Any Suggestions? Amber
"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Amber slow down youre giving me a complex . Sorry again I cant help, lets hope the "boss" responds.
Amber Woods
Ranch Hand
Joined: Mar 28, 2001
Posts: 111
posted
0
Don't worry with all the files associated with Servlets 4 and 5 I am sure to slow to a crawl real quick. Amber
Amber Woods
Ranch Hand
Joined: Mar 28, 2001
Posts: 111
posted
0
I feel like I have tried everything to make this Servlet work when a single quote gets entered but I am all out of ideas. Do I even need to worry about whether they enter the single quote or Not? If so, any suggestions on how to proceed? Amber
Johannes de Jong
tumbleweed
Bartender
Joined: Jan 27, 2001
Posts: 5089
posted
0
Amber I'll try and look at it this weekend, we have 3 day one
A servlet will interpret a single quote as a marker for the beginning or the end of the string in the textbox. You need to find a way for the servlet to recognize the single quote as just a single quote and not a marker. (I don't know what the technical word is so I am using the word "marker".) There is a class in com.javaranch.common.* that has a method that is useful for doing this. If you don't want to use that class, there is a class in the regular Java api that has a method that does the same thing.
Amber Woods
Ranch Hand
Joined: Mar 28, 2001
Posts: 111
posted
0
Thanks Daniel, I got it to work with the single quote But it took me a long time to figure out what to convert the single quote to so the browser could read it correctly. Amber
Maybe something like this will help: static String validHTML( String original ) { int ol = original.length(); StringBuffer new = new StringBuffert( ol ); char next; for ( int i = 0 ; i < ol ; i++ ) { next = original.charAt(i); if ( next == ''' ) { new.append( "&$#39"); } else if " other difficult cases etc." } More or less taken from: Professional JSP ...