This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reverse2Servlet

 
Amber Woods
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Johannes de Jong
tumbleweed
Bartender
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amber slow down youre giving me a complex .
Sorry again I cant help, lets hope the "boss" responds.
 
Amber Woods
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amber I'll try and look at it this weekend, we have 3 day one
 
Daniel Olson
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic