File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLEncoding Issue

 
Sam Kumar
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am facing one problem related to URLEncoding. In my servlet after retrieving lets say name from database...i am encoding using the URLEnoder class and generate a dynamic HTML but it seems that URLCoding is not working properly. Here is the code snippet:
String testStr = "Test'String'";
testStr = URLEncoder.encode( testStr );
System.out.println("encodedValue: " + testStr);
I verified that endoded value is:
Test%27sString
Now I am generating dynamic HTML with
out.println("<A HREF="javascript:submitForm('" + testStr + "');">Test<A>");
The generated page does not contains the encoded value, because of single quote, this link is not working:
<A HREF="javascript:submitForm('Test'String');">Test</A>
Ideally I shoould see:
<A HREF="javascript:submitForm('Test%27sString');">Test</A>
Thanks in advance!
SK
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Single quote encoding is %27 not %27s
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to printout testStr before you encode it, to ensure that the single quote made it into the string?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not cross post. Continue the conversation here.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic