简体   繁体   中英

Convert numerical representation to human readable string

I have data in my database, which represented like :

привет

It normally looks on the page (привет), for example:

<h1 class="alert alert-warning ">${flashcard.nativestring}</h1>

but in the forms input it inserts as it is. How to fix it ?

My form:

 <form:form method="POST" modelAttribute="flashcardForm" class="form-signin" >    
        <spring:bind path="nativestring">
            <div class="form-group ${status.error ? 'has-error' : ''}">
                <form:errors path="nativestring"></form:errors>
                <form:input path="nativestring" class="form-control input-lg" placeholder="Translation"></form:input>
            </div>
        </spring:bind>  

        <button class="btn btn-lg btn-primary pull-right" type="submit">Submit</button>
    </form:form>

My class method code:

Flashcard flashcard = flashService.getFlashById(id);  
model.addAttribute("flashcardForm", flashcard);  
return "flashcards/form";

Your data

&#1087;&#1088;&#1080;&#1074;&#1077;&#1090;

is html-encoding of utf-8 characters. You can convert it to a normal java string using Apache Commons Lang :

StringEscapeUtils.unescapeHtml("&#1087;&#1088;&#1080;&#1074;&#1077;&#1090;" )

I solved the problem after adding htmlEscape="false" as an attribute to my input:

<spring:bind path="nativestring">
            <div class="form-group ${status.error ? 'has-error' : ''}">
                <form:errors path="nativestring"></form:errors>
                <form:input path="nativestring" htmlEscape="false" class="form-control input-lg" placeholder="Translation"></form:input>
            </div>
        </spring:bind>

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