Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为Spring消息本地化启用外来字符?_Spring_Jsp_Localization - Fatal编程技术网

如何为Spring消息本地化启用外来字符?

如何为Spring消息本地化启用外来字符?,spring,jsp,localization,Spring,Jsp,Localization,消息已正常加载,但外来字符未按预期呈现: 我的消息属性(messages_sv.properties)是 JSP是 <%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ page import="com.ses.admin.controller.ObjectName" %> <!DOCTYPE html> <%@ taglib uri="http://www.spr

消息已正常加载,但外来字符未按预期呈现:

我的消息属性(messages_sv.properties)是

JSP是

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="com.ses.admin.controller.ObjectName" %>
<!DOCTYPE html>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="pu" tagdir="/WEB-INF/tags/node" %>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title><fmt:message key="login.title"/></title>
    <fmt:message var="jqueryUrl" key="jquery.js.url"/>
    <script src="<c:url value='${jqueryUrl}'/>" type="text/javascript"></script>
    <fmt:message var="applicationJsUrl" key="application.js.url"/>
    <script src="<c:url value='${applicationJsUrl}'/>" type="text/javascript"></script>
    <link href="/css/style.css" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Raleway:400,200" rel="stylesheet" type="text/css">
</head>
<body>

<div id="header">
    <div id="header-title"><img src="/images/logga.png">Account Administration</div>
</div>

           <div class="login">

               <hr />


                   <spring:url var="action" value="/admin/execute"/>
                   <form name='f' class="marg-left" id="inputForm" method="post" action="<c:url value='j_spring_security_check'/>" >

                   <h4 class="title"><spring:message code="login.title" /></h4>
                   <label>
                       <span><spring:message code="login.username" /></span>
                       <input type="text" name="j_username" />
                   </label>

                   <label>
                       <span><spring:message code="login.password" /></span>
                       <input type="password" name="j_password" />
                   </label>

                   <div class="buttons">
                       <button type="submit" ><spring:message code="login.title" /></button>
                       <button type="reset" ><spring:message code="login.reset" /></button>
                   </div>
                   </form>
           </div>
</body>
</html>
更新131218 20:40 CET 答案是我应该设置我所做的编码,我甚至创建了新的文件,我可以验证这些文件是否在编码中,如果我随后更改为原生文本(åäö),它将不会给出正确的结果。我能得到正确结果的唯一方法是使用转义语法,这是不可取的


属性文件必须以ISO-8859-1编码。你不能简单地用UTF-8编码一个属性文件,然后期望它能正常工作。你检查编码了吗


还有一种基于XML的属性文件格式,它更详细,但允许您使用UTF-8,而无需难看的转义语法。

谢谢!现在,它在切换到ISO-8859-1后可以工作。(我使用IntelliJ IDEA。)
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="com.ses.admin.controller.ObjectName" %>
<!DOCTYPE html>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="pu" tagdir="/WEB-INF/tags/node" %>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title><fmt:message key="login.title"/></title>
    <fmt:message var="jqueryUrl" key="jquery.js.url"/>
    <script src="<c:url value='${jqueryUrl}'/>" type="text/javascript"></script>
    <fmt:message var="applicationJsUrl" key="application.js.url"/>
    <script src="<c:url value='${applicationJsUrl}'/>" type="text/javascript"></script>
    <link href="/css/style.css" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Raleway:400,200" rel="stylesheet" type="text/css">
</head>
<body>

<div id="header">
    <div id="header-title"><img src="/images/logga.png">Account Administration</div>
</div>

           <div class="login">

               <hr />


                   <spring:url var="action" value="/admin/execute"/>
                   <form name='f' class="marg-left" id="inputForm" method="post" action="<c:url value='j_spring_security_check'/>" >

                   <h4 class="title"><spring:message code="login.title" /></h4>
                   <label>
                       <span><spring:message code="login.username" /></span>
                       <input type="text" name="j_username" />
                   </label>

                   <label>
                       <span><spring:message code="login.password" /></span>
                       <input type="password" name="j_password" />
                   </label>

                   <div class="buttons">
                       <button type="submit" ><spring:message code="login.title" /></button>
                       <button type="reset" ><spring:message code="login.reset" /></button>
                   </div>
                   </form>
           </div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/css/**" location="/css/"/>

    <mvc:annotation-driven/>
    <context:annotation-config/>
<!--
    <bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
        <property name="basenames">
            <list>
                <value>messages</value>
                <value>errors</value>
                <value>urls</value>
            </list>
        </property>
    </bean>
-->
    <bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

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

    <bean id="localeResolver"
          class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="en"/>
    </bean>

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
    </bean>

    <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
    <bean id="jsonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
    <bean id="methodHandlerExceptionResolver"
          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
        <property name="messageConverters">
            <list>
                <ref bean="stringHttpMessageConverter"/>
                <ref bean="jsonHttpMessageConverter"/>
            </list>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="assetFactory" class="com.ses.service.asset.PdfAssetFactoryImpl">
        <constructor-arg ref="partyRepository"/>
        <constructor-arg ref="customerAccountRepository"/>
        <constructor-arg name="registrationTemplatePath" value="${SES_SERVICE_ASSET_FACTORY_REGISTRATION_TEMPLATE}"/>
    </bean>
</beans>
<filter>
    <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
login.title=Logga in
login.username=Anv\u00e4ndarnamn
login.password=L\u00f6senord