0

I have a project use spring MVC, with Tiles3 use Freemarker as view engine, I have a page addItem.ftl

<div id="content">
<fieldset>
    <legend>Add Item</legend>
    <form name="item" action="add" method="post">
        <label>
            name商品名称
            <input type="text" name="name"/>
        </label><br/>
        <label>
            serialNumber
            <input type="text" name="serialCode"/>
        </label><br/>
        <label>
            weight重量
            <input type="text" name="weight"/>
        </label><br/>

        <input type="submit" value="Save"/>
    </form>
</fieldset>
<br/>
<table class="datatable">
    <tr>
        <th>Make</th>
        <th>Model</th>
    </tr>
<#list model["carList"] as Item>
    <tr>
        <td>${Item.id}</td>
        <td>${Item.name}</td>
    </tr>
</#list>

I have a form for user input and a table to pull data from database and display them dynamicly. But the page display like this enter image description here

as you can see, the Chinese I put in the ftl file are not displayed properly, but the Chinese I get from database and add to the page works fine. I'm sure my file encoding is utf-8. I suspect that it's the freeMarkerRenderer not configured properly, but I tryed all I can, just doesn't work, you can check out the whole project here github

Z.better
  • 348
  • 1
  • 5
  • 15

1 Answers1

0

Start the template with <#ftl encoding="UTF-8">, and now it should work properly. Of course it's annoying to do for each template, so instead you should set the default_encoding configuration setting to "UTF-8".

ddekany
  • 29,656
  • 4
  • 57
  • 64
  • I know you said that you are sure that your files use UTF-8 encoding, but can you triple check that? If it's still UTF-8, then I start to suspect that Tiles doesn't use the standard template loading mechanism of FreeMarker. – ddekany Apr 02 '17 at 18:57
  • I use another editor to open it and the encoding is utf-8, in intellij it displays as utf-8 either....is that enough for making sure ? where can I configure tiles's loading mechanism ...no idea – Z.better Apr 03 '17 at 05:24