struts2的国际化i18n

2024-05-27 05:32
文章标签 国际化 struts2 i18n

本文主要是介绍struts2的国际化i18n,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文主要介绍struts2的国际化,首先在struts.xml文件中配置 常量值

<constant name="struts.custom.i18n.resources" value="app"/>(app为properties部分文件名,全名为app_en_US.properties或app_zh_CN.properties)

app_en_US.propertie内容

city=NEW YORK
street=51 AVENUE
reg.error.name.null=username cannot null
reg.error.name.length=username's  length should be 5-10
country=CHINA
welcome.msg=welcome,{0}
submit=SUBMIT

app_zh_CN.properties内容

city=中国
street=山海
reg.error.name.null=用户名不能为空
reg.error.name.length=用户名长度应该在5-10之间
country=中国
welcome.msg=欢迎你,{0}
submit=注册
一.java中获取properties文件中的信息(与struts2无关,properties需直接放在src目录下)
public class Testi18n{public static void main(String [] args){ResourceBundle rb=ResourceBundle.getBundle("app",Locale.US);String city=rb.getString("city");System.out.println(city);}}
输出为  NEW YORK

二.在jsp页面中获取properties文件中的信息

i18n.jsp文件:

<%@page import="org.omg.CORBA.Request"%>
<%@ 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>
<span style="white-space:pre">	</span><hr>
<span style="white-space:pre">	</span><%
<span style="white-space:pre">		</span>request.setAttribute("name", "SIEGE");
<span style="white-space:pre">	</span>%>
<span style="white-space:pre">	</span><!--  使用s:text 标签输出国际化消息-->  
<span style="white-space:pre">	</span><s:property value="getText('street')"/>
<span style="white-space:pre">	</span> <!--使用s:param为国际化信息的占位符传入参数-->  
<span style="white-space:pre">	</span><s:text name="welcome.msg">
<span style="white-space:pre">		</span><s:param><s:property value="#request.name"/></s:param>
<span style="white-space:pre">	</span></s:text>
<span style="white-space:pre">	</span> <!-- 在表单元素中使用key来指定国际化消息的key-->  
<span style="white-space:pre">	</span><s:form>
<span style="white-space:pre">		</span>  <s:submit name="submit" key="submit" />  
<span style="white-space:pre">	</span><!--通过ognl的%符号来获取值-->
<span style="white-space:pre">		</span>  <s:submit value="%{getText('submit')}"></s:submit>
<span style="white-space:pre">	</span></s:form>
</body>
</html>

输出结果为:





这篇关于struts2的国际化i18n的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1006610

相关文章

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

struts2中的json返回指定的多个参数

要返回指定的多个参数,就必须在struts.xml中的配置如下: <action name="goodsType_*" class="goodsTypeAction" method="{1}"> <!-- 查询商品类别信息==分页 --> <result type="json" name="goodsType_findPgae"> <!--在这一行进行指定,其中lis是一个List集合,但

struts2的时候

在使用struts2的时候,我们在jsp中经常写这样的代码片段:      学生姓名:            考试名称:            考试分数:         其中studentScores.student.stuName是对应后台action的熟悉,action是这样写的   public class StudentExamAc

Struts2常用标签总结--转载

Struts2常用标签总结 一 介绍 1.Struts2的作用 Struts2标签库提供了主题、模板支持,极大地简化了视图页面的编写,而且,struts2的主题、模板都提供了很好的扩展性。实现了更好的代码复用。Struts2允许在页面中使用自定义组件,这完全能满足项目中页面显示复杂,多变的需求。 Struts2的标签库有一个巨大的改进之处,struts2标签库的标签不依赖于

Struts2和Spring整合中出现的问题

今天做了一个Struts2和Spring整合的练习,中间出了一点问题,贴出来供其它人参考。(该文章写于2010年) 代码写好后启动Tomcat服务器时报错: 严重: Exception starting filter struts2java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeExceptio

struts2接受中文乱码

问题描述: Action中有某一属性,并设有响应的getter/setter方法,前台提交中文数据时Action接收乱码。 解决方案: 1.在struts.xml中加入 <constant name="struts.i18n.encoding" value="UTF-8"></constant> 2.然后打开tomcat目录下conf文件夹下的server.xml文件

有关struts2

struts2的一点认识: (1)实现了MVC,将应用进行模块化管理,耦合性降低 (2)另外还实现了插件式的功效,比如拦截器的增加与减少,只用在配置文件里进行配置 (3)方便的访问sevlet里的重要属性 (4)方便的进行数据类型转换,当然也可进行自定义的转换 另外它还支持文件的上传与下载,对Ajax的支持。 上面的这些不知道是自己总结的还是在网上找的,在这里记录下。

struts2 struts.xml常用常量配置

<constant name="struts.i18n.encoding" value="UTF-8" /> 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 <constant name="struts.ui.theme" value="simple" /> 设置页面struts标签的样式     <consta

struts2 result type= redirect redirectAction chain dispatcher等类型

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.