The international resource file configured by springmvc displays the error causes of?? key???

 Overview:

Use JSTL & lt in the JSTL view parser of spring mvc; fmt: message key =”& gt; & lt; / FMT & gt; display correctly without binding, but show errors in the titleMistaken,

Usually we encounter scrambling code is a direct check coding problem, for this I delayed nearly 3 hours, really hateful, it is good to bind directly here;

 

1 <fmt:bundle basename="messages">
2      <fmt:message key="messages.username"></fmt:message>
3      </fmt:bundle> 

 

Outline diagram:

 

Basic configuration diagram:

This is only a corresponding function. You need to know spring MVC.

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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-4.3.xsd">
    
    <context:component-scan base-package="restcrud"></context:component-scan>
    <context:component-scan base-package="converters"></context:component-scan>
    <context:component-scan base-package="springmvctest"></context:component-scan>
    <context:component-scan base-package="religon"></context:component-scan>
        <!-- In the actual development, mvc:annotation-driven tags --> are usually required.<bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/view/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    
    <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
    <!-- Custom type conversion supports formatting and custom type conversion --><! - < bean id="conversionService"  class="org.springframework.context.support.ConversionServiceFactoryBean"> Formatting annotation --> is not supported.< bean id="conversionService"  class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
        <property name="converters">
            <set>
            <ref bean="rmployeeConverter"/>
            </set>
        </property>
    </bean>
    <!-- Static file -->< mvc:default-servlet-handler/>
    
    <!-- Internationalization document -->< beanclass="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages"></property>
                   <!-- Chinese --> supporting UTF-8;<! - < property name="defaultEncoding" value="UTF-8"/>
         <property name="useCodeAsDefaultMessage" value="true" /> -->
        <property name="cacheSeconds" value="0"/>
         <property name="defaultEncoding" value="iso-8859-1" />
    </bean>
    
    <!-- Configuring --> to display nationalized documents;< mvc:view-controller path="/CN" view-name="CN"/> 
    <mvc:view-controller path="/US" view-name="US"/>
    <!-- <mvc:view-controller path="/linker" view-name="linker"/> -->
    
    
    <!-- Support hyperlink internationalization -->< bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
           <property name="defaultLocale" value="zh_CN"></property>
    </bean>
    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>
    </mvc:interceptors>

</beans>

 

 

 

 jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>??</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
    <fmt:bundle basename="messages">
     <fmt:message key="messages.username"></fmt:message>
     </fmt:bundle> 
    <br>
    Switch to Chinese:<a href="linker?locale=zh_CN">Chinese < /a> < br>
     Switch English:<a href="linker?locale=en_US">English < /a>< /body>< /html>

 

Locale

 

static public final Locale TAIWAN = TRADITIONAL_CHINESE;

    /** Useful constant for country.
     */
    static public final Locale UK = createConstant("en", "GB");

    /** Useful constant for country.
     */
    static public final Locale US = createConstant("en", "US");

    /** Useful constant for country.
     */
    static public final Locale CANADA = createConstant("en", "CA");

    /** Useful constant for country.
     */
    static public final Locale CANADA_FRENCH = createConstant("fr", "CA");

    /**

 

Leave a Reply

Your email address will not be published. Required fields are marked *