We have a function strip_tags
in PHP which would strip all the tags and also you can exempt certain tags from being stripped out..
My question is whether there is anything similar in Java??
You could try using the JSoup library. That API provides a clean
method:
For examples, have a look over here: Sanitize untrusted HTML:
String unsafe =
"<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>";
String safe = Jsoup.clean(unsafe, Whitelist.basic());
// now: <p><a href="http://example.com/" rel="nofollow">Link</a></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With