Display special character

I have problem when user key in single quote or double quote in textfield and view it in textfield. I am using jsp where by I put the code like this

user input >>

display output >>

It saved successfully in Oracle database , but problem happen when it want to display in input field.

Then I change my code into

Yes, it save a day but only for awhile because the user might be key in input such

user input >>

display output >>

See, it cannot read the double quote because it stop at double quote.

At last this morning, I found out the solution.
public String convSpecialChar(String htmlString)
   htmlString = htmlString.replaceAll("\\<.*?\\>", "");
  htmlString = htmlString.replaceAll("\r", "
  htmlString = htmlString.replaceAll("\n", "
  htmlString = htmlString.replaceAll("\"",""");
  htmlString = htmlString.replaceAll("\'","'");
  htmlString = htmlString.replaceAll(",",",");
   return htmlString;
So I called it like below :

So I have no problem with double quote,single quote and maybe some other special character. I think maybe there other way effective way to do this but somehow this code save me for a while


Popular Posts