I have written a small JSP page that contains a text box and a button. What I am attempting to do is to display whatever I have written in the text box (which is a String) once i click the button. It has worked for all scenarios but did not work for the one scenario where I put the string within double quotes (” “). Is there any way I can make that work?
For example: If I write abcd within the text box, it works fine. But if I write “abcd” (i.e with double quotes), then the text within the double quotes don’t display.
I understand why that is happening (example: If we write abcd in the text box, it is taken as “abcd” and if I write “abcd” within the text box, it is taken as “”abcd””), but couldn’t find a solution for that.
Or is there a solution for that at all?
Yes – escape the quotes. You should replace them with
"A ready-to-use solution that will cover some more cases is commons-lang
StringEscapeUtils.escapeHtml(str)