Struts2--国际化
Struts对国际化的支持表现在三个地方:
|-UI标签
|-验证通知的消息和错误
|-在action类里面通过getText()方法
要实现Struts的国际化,首先,需要在struts.xml配置文件中加入如下配置:
<constant name="struts.custom.i18n.resources" value="fuwh"></constant>
然后在src文件夹下写两个用于实现国际化的配置文件
·fuwh_zh_CN.properties
city=\u6b22\u8fce\u8001\u5085\u6765\u5230\u4e0a\u6d77{0}
name=\u5ba2\u670d
·fuwh_en_US.properties
city=welcome laofu to shanghai{0}
name=kefu
最后编写页面文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<s:text name="name"></s:text>:
<s:text name="city">
<s:param>888888</s:param>
</s:text>
<s:property value="getText('name')"/>
</body>
</html>
这样就可以根据本地的语言环境来选择显示的内容了,实现国际化编程


浙公网安备 33010602011771号