struts2学习(10)struts2国际化
一、国际化简介:

二、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国际化的更多相关文章
- Struts2学习一----------Struts2的工作原理及HelloWorld简单实现
© 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...
- struts2 学习记录 过滤器 国际化
struts2接触不是一天两天了,但是一直没有用它做什么项目,但老师确一直说它有很大的学习价值,所以还是把我学习到的东西给记录一下,记录的东西没有规律,只是给自己留个备份, struts2中最关键的是 ...
- Struts2学习笔记(八)——国际化
1.Struts2国际化介绍 国际化即internationalization简称i18n. 为了实现程序的国际化,必须先提供程序所需要的资源文件.资源文件的内容是key-value键值对. 资源文件 ...
- struts2学习(11)struts2验证框架1.验证简介、内置验证
一.Struts2验证简介: 二.struts2内置验证: 下面例子,需求是:为用户注册进行验证: com.cy.model.User.java: package com.cy.model; publ ...
- Struts2学习七----------Struts2后缀
© 版权声明:本文为博主原创文章,转载请注明出处 Struts2后缀 - Struts2默认后缀是action - Struts2使用默认后缀时*.action和*都是同一个请求 - Struts2自 ...
- Struts2学习笔记--Struts2的体系结构
1. Struts2体系结构 Struts是以前端控制器框架为主体的框架,用户的请求会通过控制器选择不同的Action类来执行具体的操作,在Action类中所有的Servlet对象(request.r ...
- Struts2学习笔记——Struts2与Spring整合
Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...
- struts2学习(2)struts2核心知识
一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...
- struts2学习(1)struts2 helloWorld
一.struts2简介: 二.helloWorld: 1)工程结构: HelloWorldAction.java: package com.cy.action; import com.opensymp ...
随机推荐
- Prism 4 文档 ---第5章 实现MVVM模式
MVVM模式有助于清楚的区分应用程序界面的业务层和展现层.保持一个清晰的应用程序逻辑和UI分离有助于处理开发和设计过程中大量的问题,同时,使得应用程序的测试,维护,和扩展更加容易.MVVM也可 ...
- Viewpager+Fragmnet懒汉式注意
1.new的时候不会触发setUserVisibleHint(): 2.setUserVisibleHint()在ViewPager中当前缓冲页跳转,可见到不可见或者不可见到可见的时候触发: 3.ge ...
- python虚拟环境的搭建命令mkvirtualenv
windows环境如果同时安装了python3和python2,那么无论在哪个版本安装了virtualenv和virtualenvwrapper-win 通过以下命令设置ptyhon版本路径,即可建立 ...
- certbot以standalone方式新建密钥
下载:wget https://dl.eff.org/certbot-auto 授权:chmod a+x ./certbot-auto 快捷命令 ./certbot-auto certonly --t ...
- SpringInAction--自动化装配(显示装配之 java注解配置)
Spring在配置时候有三种方案可选 1.在xml中进行显示配置 2.在java中进行显示配置 3.隐式的Bean发现机制和自动装配 今天学习的 第二种—— 在java中进行显示配置 场景: 尽管在很 ...
- 查询表名及列名长度超过一定长度的SQL
apple=# select * from (select a.relname, char_length(a.relname) as tb_name_length, b.attname, char_l ...
- 深度学习(六十六)生成模型、最大化似然、KL散度
- chrome浏览器使用记录
出现错误 net::ERR_BLOCKED_BY_CLIENT 出现这个错误一般是因为chrome安装了adblocker等这样的插件,这些插件会把路径及文件名中包含广告字样的文字禁止掉,比如:adv ...
- (转)如何转载CSDN的文章
前言 对于喜欢逛CSDN的人来说,看别人的博客确实能够对自己有不小的提高,有时候看到特别好的博客想转载下载,但是不能一个字一个字的敲了,这时候我们就想快速转载别人的博客,把别人的博客移到自己的空间 ...
- js之方向检测
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...