wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes 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 "Reverse2Servlet" Watch "Reverse2Servlet" New topic
Author

Reverse2Servlet

Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
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
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
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
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
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
Amber I'll try and look at it this weekend, we have 3 day one
Daniel Olson
Ranch Hand

Joined: Jan 05, 2001
Posts: 81
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
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
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
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 ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reverse2Servlet