惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - BearOcean

LOG.ZS.0001.基于Freetype的游戏字体渲染优化思路 const 和指针 C++ 下啥时候用struct, 啥时候用class C++ 和 Java 中的变参 解决站点关键数据,状态数据,无须持久化数据的一些思路 - BearOcean BS程序代码与安全与基本攻击/防御模式 Ant 阅读笔记 进度,效率,与个人事务管理 Personal Task 1.0 MySql与Java的时间类型 数据挖掘概述 解决Thread 的关闭问题和参数传递时想到的办法. Command 模式 .Net标准控件与自定义控件(2) ToolTipButton 内网聊天工具FreeChat 2.0 FreeChat 2.0 ...大改 模型和架构 局域网聊天工具FreeChat 1.0 开发日志 - BearOcean 内网聊天工具FreeChat Beta 为Socket写的附加方法 .Net 事件
Struts 实现的I18N
BearOcean · 2008-05-09 · via 博客园 - BearOcean


struts 和I18n:
就是 International 后面18个字符。。具体意义省略。
其实现原理是:
服务端维护多套对应的资源文件,对应于不同的语言(这些资源文件独立于代码存在)。
访问发送到服务器时,服务器自动识别客户端所使用的语言环境。
服务器根据客户的语言环境选择合适的资源,渲染入视图,然后返回给客户端。

struts 实现I18n
struts的struts-config 里可以定义一个
<message-resources> element, 该标志能够导致struts引用到不同的资源文件。

实现的方式很简单:
MessageResources_zh_CN
message.hello=hello..(cn)

sturts-config.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

    <form-beans>
    </form-beans>

    <global-exceptions>
    </global-exceptions>

     <action-mappings>
   <action path="/view"
     type="com.bss.test.i18n.ActionI18N">
     <forward name="success" path="/ui/view.jsp" redirect="false" />
   </action>

       </action-mappings>

    <message-resources key="lala" parameter="com.bss.test.i18n.MessageResources" />
</struts-config>

view.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<b>This page is for test I18n.<b><br>
Message:&nbsp;
<bean:message key="message.hello" bundle="lala"/>
</body>
</html>

这里,这个<message-resources key="lala" parameter="com.bss.test.i18n.MessageResources" />
和<bean:message key="message.hello" bundle="lala"/>中的lala想对应,也就是说,可以有多个不同的MessageSources.
只要他们<message-resources key="lala" parameter="com.bss.test.i18n.MessageResources" />中的key不一样就可以了。
可以自由的安排配置文件的部署。