配置Spring文件(dispatcher-servlet.xml)
<?xml version="1.0" encoding="UTF-8"?>mvc:annotation-driven/ mvc:default-servlet-handler/ <context:component-scan base-package=“controller”/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/><!-- 前缀 --> <property name="suffix" value=".jsp"/><!-- 后缀,自动拼接 --> </bean> 添加多语言的配置文件 添加language_en_US.properties到src目录下 language.cn = \u4e2d\u6587 language.en = English internationalisation = \u0020Internationalisation welcome = This is the English environment introduce= This is I18N Demo添加language_zh_CN.properties到src目录下 language.cn = \u4e2d\u6587 language.en = English internationalisation = \u56fd\u9645\u5316 welcome = \u8fd9\u662f\u4e2d\u6587\u73af\u5883 introduce= \u8fd9\u662f\u56fd\u9645\u5316\u7684\u4e8b\u4f8b
加入i18n 过滤器到配置文件中 将配置添加到dispatcher-servelet中
mvc:interceptors </mvc:interceptors>
在页面中使用多语言 在Controller中添加路径 @Controller public class HelloController { @RequestMapping("/hello.action") public String index() { return “hello”; } }
在JSP页面中使用 通过<spring:message code=“welcome”/>将配置文件中的内容读取 <%@ page language=“java” contentType=“text/html; charset=UTF-8”%> <%@taglib prefix=“spring” uri=“http://www.springframework.org/tags” %>
SpringMVC Language:访问该项目的/hello.action,通过链接可以切换语言 中文
英文
项目结构
作者:呜呜呜啦啦啦 来源: 原文:https://blog.csdn.net/u013360850/article/details/70860144 版权声明:本文为博主原创文章,转载请附上博文链接!