Struts2--國際化
阿新 • • 發佈:2017-09-22
.org Coding 通知 page tle htm doctype utf-8 fix
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>
這樣就可以根據本地的語言環境來選擇顯示的內容了,實現國際化編程
Struts2--國際化