简体   繁体   中英

How to create custom emoji's in Java?

I have a web based project using spring mvc outputting into jsp's. I want to be able to type :) and have it replaced with a picture of my trainers face. How would I do this? I can't find any questions on here that are either relevant nor guides on the Internet.

Thanks, John

What you want to do is convert user entered text into HTML, then replace the :) string with an image of your trainers face.

Note: It's very important to escape text when displaying it again as HTML, in order to prevent cross-site scripting (XSS) attacks. Usually you use <c:out> to automatically do this escaping for you.

Since you want some HTML in the text, you can't use <c:out> , so you have to escape the rest of the text. See this page for ideas of how to do that: Best way to encode text data for XML in Java?

Then you replace the :) with an image tag: <img src="trainer.png"> , and of course add that image file to your webapp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM