2013-07-29 2 views
0

Freemarker가 내 템플릿 파일을 UTF-8로 구문 분석하려고하지만 Cp1252로 파싱하는 것으로 보입니다.freemarker 템플릿에서 <#ftl> 지시어 사용

2013-07-30 00:00:00.984 DEBUG freemarker.cache:? Could not find template in cache, creating new one; id=["myFile.ftl"["es_MX",Cp1252,parsed] ] 

검색 한 결과 found that adding the FTL directive을 입력하면 인코딩을 지정할 수 있습니다.

<#ftl encoding="UTF-8"> 
Estimado Usuario, 
Testing this content! 
<#/ftl> 

을하지만 로그에이 얻을 :

그래서 같은 (메모장에서 BOM ++와 UTF-8로 저장) 템플릿 파일에 추가.

MessageTemplateException [message=Unable to process template due to Encountered "<#ftl " at line 1, column 4 in myFile.ftl. 
Was expecting one of: 
    <EOF> 
    <ATTEMPT> ... 
    <IF> ... 
    <LIST> ... 
    <FOREACH> ... 
    <SWITCH> ... 
    <ASSIGN> ... 
    <GLOBALASSIGN> ... 
    <LOCALASSIGN> ... 
    <_INCLUDE> ... 
    <IMPORT> ... 
    <FUNCTION> ... 
    <MACRO> ... 
    <TRANSFORM> ... 
    <VISIT> ... 
    <STOP> ... 
    <RETURN> ... 
    <CALL> ... 
    <SETTING> ... 
    <COMPRESS> ... 
    <COMMENT> ... 
    <TERSE_COMMENT> ... 
    <NOPARSE> ... 
    <BREAK> ... 
    <SIMPLE_RETURN> ... 
    <HALT> ... 
    <FLUSH> ... 
    <TRIM> ... 
    <LTRIM> ... 
    <RTRIM> ... 
    <NOTRIM> ... 
    <SIMPLE_NESTED> ... 
    <NESTED> ... 
    <SIMPLE_RECURSE> ... 
    <RECURSE> ... 
    <FALLBACK> ... 
    <ESCAPE> ... 
    <NOESCAPE> ... 
    <UNIFIED_CALL> ... 
    <WHITESPACE> ... 
    <PRINTABLE_CHARS> ... 
    <FALSE_ALERT> ... 
    "${" ... 
    "#{" ... 
with inputs of {loginUrl=testURL} in myFile.ftl with locale es_MX, code=SUCCESS, arguments=[]] 

어쩌면 내가 제대로하지 않을 것입니까?

답변

1

BOM을 사용하지 마십시오. </#ftl>도 사용하지 말고 <#ftl> 만 있습니다. 가장 중요한 점은 대부분의 템플릿이 UTF-8 인 경우 FreeMarker의 기본 인코딩을 봄 (예 : <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">...<property name="freemarkerSettings">...<props>...<prop key="default_encoding">UTF-8</prop>)으로 설정하기 때문에 #ftl을 사용할 필요가 없기 때문입니다.

관련 문제