一、国际化简介:

二、struts2国际化设置:

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="i18n"></constant> </struts>

上面取的value为‘i18n’,默认加载的资源文件名字为i18n.properties;  默认语言采用中文;

中文加载的资源文件为:i18n_zh_CN.properties;

英文加载的资源文件为:i18n_en_US.properties;

i18n.properties:

因为中文放在properties中使用unicode编码,userName对应的是'用户名'.......

{0}指的是第0个位置,参数的占位符。

userName=\u7528\u6237\u540d
password=\u5bc6\u7801
login=\u767b\u5f55
welcomeInfo=\u6b22\u8fce{0}

i18n_zh_CN.properties:

userName=\u7528\u6237\u540d
password=\u5bc6\u7801
login=\u767b\u5f55
welcomeInfo=\u6b22\u8fce{0}

i18n_en_US.properties:

userName=userName
password=password
login=login
welcomeInfo=welcome{0}

login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td><s:text name="userName"></s:text></td>
<td>
<input type="text"/>
</td>
</tr>
<tr>
<td><s:text name="password"></s:text></td>
<td>
<input type="text"/>
</td>
</tr>
<tr>
<td>
<input type="button" value="<s:text name='login'></s:text>"/>
</td>
</tr>
</table>
</body>
</html>

welcome.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:text name="welcomeInfo">
<s:param>Jack</s:param>
</s:text>
</body>
</html>

中文测试:

英文测试:

struts2学习(10)struts2国际化的更多相关文章

  1. Struts2学习一----------Struts2的工作原理及HelloWorld简单实现

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...

  2. struts2 学习记录 过滤器 国际化

    struts2接触不是一天两天了,但是一直没有用它做什么项目,但老师确一直说它有很大的学习价值,所以还是把我学习到的东西给记录一下,记录的东西没有规律,只是给自己留个备份, struts2中最关键的是 ...

  3. Struts2学习笔记(八)——国际化

    1.Struts2国际化介绍 国际化即internationalization简称i18n. 为了实现程序的国际化,必须先提供程序所需要的资源文件.资源文件的内容是key-value键值对. 资源文件 ...

  4. struts2学习(11)struts2验证框架1.验证简介、内置验证

    一.Struts2验证简介: 二.struts2内置验证: 下面例子,需求是:为用户注册进行验证: com.cy.model.User.java: package com.cy.model; publ ...

  5. Struts2学习七----------Struts2后缀

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2后缀 - Struts2默认后缀是action - Struts2使用默认后缀时*.action和*都是同一个请求 - Struts2自 ...

  6. Struts2学习笔记--Struts2的体系结构

    1. Struts2体系结构 Struts是以前端控制器框架为主体的框架,用户的请求会通过控制器选择不同的Action类来执行具体的操作,在Action类中所有的Servlet对象(request.r ...

  7. Struts2学习笔记——Struts2与Spring整合

      Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...

  8. struts2学习(2)struts2核心知识

    一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...

  9. struts2学习(1)struts2 helloWorld

    一.struts2简介: 二.helloWorld: 1)工程结构: HelloWorldAction.java: package com.cy.action; import com.opensymp ...

随机推荐

  1. Marketing™Series用户手册(Marketing™Series Manual)

    起源(Origin) 每日构建(Daily Build) 软件不支持的功能(Functions which are not supported.) 软件支持的功能(Functions which ar ...

  2. tornado源码分析系列一

    先来看一个简单的示例: #!/usr/bin/env python #coding:utf8 import socket def run(): sock = socket.socket(socket. ...

  3. APUE学习笔记——6 系统数据文件与信息

    1.用户口令:/etc/passwd文件 该文件中包含下列结构体信息.其中,当下主修熊passwd不再这里显示,是使用了一个占位符. struct passwd { char * pw_name; / ...

  4. vue.js 源代码学习笔记 ----- instance state

    /* @flow */ import Dep from '../observer/dep' import Watcher from '../observer/watcher' import { set ...

  5. iOS NSRunloop

    什么是Runloop Runloop即运行循环.为什么你的APP放在那里不去动它,在某个时间点去操作它,它还会给你反馈.就是因为Runloop的存在. 总结一下,因为Runloop的存在,保证你的程序 ...

  6. java之对象的前世今生

    Tips 对象存在与堆上,实例变量的值存在于对象中.实例变量存在于对象所属的堆空间中. 局部变量与对象方法存在于栈中. 创建对象的时候有如下代码 Dog d = new Dog(); 其中的Dog() ...

  7. 诗·想——日记&断章

    日记      海子 姐姐,今夜我在德令哈,夜色笼罩 姐姐,我今夜只有戈壁 草原尽头我两手空空 悲痛时握不住一颗泪滴 姐姐,今夜我在德令哈 这是雨水中一座荒凉的城 除了那些路过的和居住的 德令哈... ...

  8. (转)读懂diff

    http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.html diff是Unix系统的一个很重要的工具程序. 它用来比较两个文本文件的差异, ...

  9. sublime忽略打开工程中某些文件夹,不在搜索之列

    { "folders": [ { "follow_symlinks": true, "path": ".", " ...

  10. daemon Thread

    1.概念 守护进程(daemon)是指在UNIX或其他多任务操作系统中在后台执行的电脑程序,并不会接受电脑用户的直接操控.此类程序会被以进程的形式初始化.守护进程程序的名称通常以字母“d”结尾:例如, ...