简体   繁体   中英

HTML content to a string with regular expressions

I need to compose an email body and have user name password atributes to be added of every user to it. For now i have the html content in a string and im trying to have string formatter to replace the user name and password for the respective user. How ever I am having trouble having the html content in a single string and also get the mapping of diferent users to be changed accordingly.

code snipet

String regEmailBody =
        "<div>
            + "successfully registered for the system. <br>Your username " 
            + "is[@email_placeholder].<br>Your temporary password is <b>"
            + "@sysGeneratedPW_placeholder!</b><br>Please login to the system to reset your password, "
            + "click on the button below.<br></p></div>"; 


    regEmailBody.replaceFirst("@name_placeholder", name); 
    regEmailBody.replaceAll("@userEmail", emailAdd); 

Strings in java are immutable. In your code, you are producing new strings with replaced parts, but you are not storing them anywhere.

regEmailBody = regEmailBody.replaceFirst("@name_placeholder", name);

(the example code are also missing a " after the div, and the placeholder strings does not correspond with what you're trying to replace.)

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