Freemarker nie wyświetla polskich znaków na stronie.

0

Witam. Używam freemarkera w mojej aplikacji, ale niestety nie wyświetla mi polskich znaków tylko krzaczki. Wydaje mi się, że ustawiłem wszystko jak potrzeba.

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<tx:annotation-driven transaction-manager="transactionManager" />

	<!-- DispatcherServlet Context: defines this servlet's request-processing 
		infrastructure -->
	<context:component-scan base-package="pl.piotr.ibank" />

	<!-- Enables the Spring MVC @Controller programming model -->
	<annotation-driven />
	<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
		up static resources in the ${webappRoot}/resources directory -->
	<resources mapping="/resources/**" location="/resources/" />

	<beans:bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<beans:property name="templateLoaderPath" value="/" />
		<beans:property name="defaultEncoding" value="UTF-8" />
	</beans:bean>

	<beans:bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<beans:property name="viewResolvers">
			<beans:list>
				<beans:bean id="viewResolver"
					class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
					<beans:property name="prefix" value="/WEB-INF/views/" />
					<beans:property name="suffix" value=".ftl" />
					<beans:property name="contentType" value="text/html;charset=UTF-8" />
				</beans:bean>
			</beans:list>
		</beans:property>
	</beans:bean>

	<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
		in the /WEB-INF/views directory <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
		<beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property 
		name="suffix" value=".jsp" /> </beans:bean> -->

	<beans:bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<beans:property name="basename" value="classpath:i18n/messages" />
		<beans:property name="defaultEncoding" value="UTF-8" />
	</beans:bean>

	<beans:bean id="localeResolver"
		class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
		<beans:property name="defaultLocale" value="pl_PL" />
	</beans:bean>

	<interceptors>
		<beans:bean id="localeChangeInterceptor"
			class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
			<beans:property name="paramName" value="lang" />
		</beans:bean>
	</interceptors>

	<beans:bean id="viewResolver1"
		class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
		<beans:property name="order" value="1" />
		<beans:property name="basename" value="views" />
	</beans:bean>

</beans:beans>
 

zaś na stronie dałem:

<#ftl encoding='UTF-8'>
<#import "/spring.ftl" as spring /> 

Jeszcze jedno pytanie. Piszę w eclipse i niestety nie obsługuj on plików ftl i muszę je tworzyć przez create new file i odpowiednio nazywać plik. Tylko, że potem cała strona wygląda jakby była napisana w notatniku żadnych wyróżnień itp. nie tak jak jest np. w podglądzie plików jsp. Czy da się coś z tym zrobić? Szukałem jakichś pluginów w marketplace ale nic nie znalazłem.

1
  1. https://github.com/Pharisaeus/SpringScaffoldApplication ;)
    Szczególnie w web.xml
    <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Bo tego ci chyba brakuje (nie wiem, nie pokazałeś web.xmla)
2. IntelliJ :)

0

Mam to w web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<!-- The definition of the Root Spring Container shared by all Servlets 
		and Filters -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
		/WEB-INF/spring/root-context.xml
		/WEB-INF/spring/security-config.xml
		</param-value>

	</context-param>

	<!-- Creates the Spring Container shared by all Servlets and Filters -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- Processes application requests -->
	<servlet>
		<servlet-name>appServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>
			/WEB-INF/spring/appServlet/servlet-context.xml
			</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>appServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<filter>
		<filter-name>springSecurityFilterChain</filter-name>
		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>springSecurityFilterChain</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	 <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
 

Dla stron jsp wyświetla polskie litery, ale przy flt mam krzaki.

Edit: pomogła zmiana kodowania w eclipsie z cp-125 na UTF-8.

0

Jest chyba plugin do freemarkera (niestety ubogi bardzo) z Jboss Tools, sprawdz.

1 użytkowników online, w tym zalogowanych: 0, gości: 1