问题概述:

在spring mvc 的jstl view 视图解析器中 使用jstl <fmt:message key=”“”></fmt> 不不要绑定也可以正常显示,这里却显示标题上的错误,

一般我们遇到乱码都是直接排查编码问题,为此我耽误接近3小时,真是可恨,这里直接绑定就好;

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

大纲图:

基本配置图:

这里只是起到对应作用,前提你要会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>
<!-- 在实际开发中通常都需配置 mvc:annotation-driven 标签 -->
<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>
<!-- 自定义类型转换 支持格式化 与自定义类型转换 -->
<!-- <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> 不支持格式化注解 -->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<ref bean="rmployeeConverter"/>
</set>
</property>
</bean>
<!-- 静态文件 -->
<mvc:default-servlet-handler/> <!-- 国际化文件 -->
<bean class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"></property>
<!-- 支持UTF-8的中文 -->
<!-- <property name="defaultEncoding" value="UTF-8"/>
<property name="useCodeAsDefaultMessage" value="true" /> -->
<property name="cacheSeconds" value=""/>
<property name="defaultEncoding" value="iso-8859-1" />
</bean> <!-- 配置展示国家化文件的 -->
<mvc:view-controller path="/CN" view-name="CN"/>
<mvc:view-controller path="/US" view-name="US"/>
<!-- <mvc:view-controller path="/linker" view-name="linker"/> --> <!-- 支持超连接国际化 -->
<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="">
<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>
切换中文:
<a href="linker?locale=zh_CN">中文</a><br>
切换英文:
<a href="linker?locale=en_US">英文</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"); /**

springmvc配置的国际化资源文件显示为???key???的错误原因的更多相关文章

  1. springmvc国际化资源文件

    spring配置文件中添加 <!-- 配置国际化资源文件 --> <bean id="messageSource" class="org.springf ...

  2. java后台获取国际化资源文件

    //current属性,由于此属性只做赋值操作,不做取值操作,因此没有get方法 private Locale current; public void setCurrent(Locale cur) ...

  3. 42.国际化-配置package的资源文件

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 同样在建立com.asm包下建立两个资源文件(package级别的资源文件名 ...

  4. SpringMVC+FreeMarker实现静态资源文件自动添加版本号(md5)

    近日切换java开发,开始学习springframework.在实现静态资源文件自动计算版本号的实例时,因为不熟悉框架,走了不少弯路,好在最终解决了问题.这里写篇文章记录一下实现,也希望对大家有些用处 ...

  5. ASP.NET Core中结合枚举和资源文件显示列表

    模型类的某些属性以枚举形式出现,我们希望在打开编辑表单时在选择列表中显示枚举值.有时我们想要枚举元素名称,但有时我们想要使用自定义名称甚至翻译. 这个例子演示了如何获取枚举元素名称以选择ASP.NET ...

  6. spring boot 配置虚拟静态资源文件

    我们实现的目的是:通过spring boot 配置静态资源访问的虚拟路径,可实现在服务器,或者在本地通过:http://ip地址:端口/资源路径/文件名  ,可直接访问文件 比如:我们本地电脑的:E: ...

  7. 配置linux命令行界面的 文件显示颜色

    在linux命令行界面下使用ls命令时,有时会看见显示的文件会有不同的颜色,因为linux的文件没有后缀名这个概念(Windows系统中的文件会有后缀名,从而可以将文件标识为不同类型),显示不同的颜色 ...

  8. 在Win7中IIS配置Asp.Net虚拟文件夹的方法及错误总结!

    在Win7中IIS配置Asp.Net虚拟文件夹的方法总结! 一.右键[站点].点击[加入虚拟文件夹]或[虚拟应用程序],笔者建议最好建立虚拟应用程序,由于这就跟一个站点差点儿相同.不用考虑路径问题. ...

  9. SpringMVC 部署项目静态资源文件访问问题

    问题:采用SpringMVC 部署项目后程序加载或用浏览器访问时出现类似的警告,2011-01-19 10:52:51,646 WARN [org.springframework.web.servle ...

随机推荐

  1. [干货]兼容HTML5的Placeholder属性-更新版v0.10102013

    HTML5对Web Form做了许多增强,比如input新增的type类型.Form Validation等.Placeholder是HTML5新增的另一个属性,当input或者textarea设置了 ...

  2. 机器视觉 之 Gabor Feature

    在机器视觉中,gabor feature是一种比较常见的特征,因为其可以很好地模拟人类的视觉冲击响应而被广泛应用于图像处理, gabor feature 一般是通过对图像与gabor filter做卷 ...

  3. onhashchange

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 1139 First Contact(30 分)

    Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle i ...

  5. BZOJ_3529_[Sdoi2014]数表_莫比乌斯反演+树状数组

    Description 有一张 n×m 的数表,其第 i 行第 j 列(1 <= i <= n, 1 <= j <= m)的数值为 能同时整除 i 和 j 的所有自然数之和.给 ...

  6. javacpp-FFmpeg系列之2:通用拉流解码器,支持视频拉流解码并转换为YUV、BGR24或RGB24等图像像素数据

    javacpp-ffmpeg系列: javacpp-FFmpeg系列之1:视频拉流解码成YUVJ420P,并保存为jpg图片 javacpp-FFmpeg系列之2:通用拉流解码器,支持视频拉流解码并转 ...

  7. Python3解leetcode Valid Parentheses

    问题描述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if th ...

  8. win7 64位搭建Mantis 缺陷管理系统

    什么是Mantis MantisBT is a free popular web-based bugtracking system (feature list). It is written in t ...

  9. hadoop--谷歌三大论文

    学习大数据必读的三个论文: http://pan.baidu.com/s/1c0FA69U 在我的网盘,大家可以去下载 Google File System中文版 Google Bigtable中文版 ...

  10. java 发邮件 代码

    /** * java发送带附件的邮件 * 周枫 * 2013.8.10 */ package com.dsideal.Util; import javax.mail.*; import javax.m ...