Struts2(11)_Struts2 国际化

本系列博客汇总在这里:Struts2 汇总


源码工程文件为:struts2_13

一、建立独立的包的资源文件

命名的规范:以 msg 开头后面加上国家的语言和国家名称的简写。

msg_en_US.properties
msg_zh_CN.properties

在这里插入图片描述
在这里插入图片描述

二、配置国际化资源文件的加载

<!-- 
	加载资源文件做国际化,value指的是资源文件的包的路径后面加上msg,用/分隔
-->
<constant name="struts.custom.i18n.resources" value="com/wyx/resource/msg"></constant>

三、在页面上使用国际化的资源<s:text name=’属性文件的key’>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!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>
	
	<form action="${pageContext.request.contextPath }/person/weiyuxuan" method="post">
		<table>
			<tr>
				<td>ID</td>
				<td><input type="text" name="id"></td>
				<td><s:fielderror fieldName="id"></s:fielderror></td>
			</tr>
			<tr>
				<td><s:text name="pname"/></td>
				<td><input type="text" name="name"></td>
				<td><s:fielderror fieldName="name"></s:fielderror></td>
			</tr>
			<tr>
				<td><s:text name="pgender"/></td>
				<td>
					<input type="radio" name="gender" value="1" checked="checked"><input type="radio" name="gender" value="2"></td>
				<td></td>
			</tr>
			<tr>
				<td><s:text name="paddr"/></td>
				<td><input type="text" name="address"></td>
				<td><s:fielderror fieldName="address"></s:fielderror></td>
			</tr>
			
			<tr>
				<td><s:text name="pbirth"/></td>
				<td><input type="text" name="birthday"></td>
				<td><s:fielderror fieldName="birthday"></s:fielderror></td>
			</tr>
		</table>
		<input type="submit" value="<s:text name='submit'/>">
	</form>
</body>
</html>

四、效果演示

在这里插入图片描述

如有错误,欢迎指正!

发布了448 篇原创文章 · 获赞 210 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_36260974/article/details/103713362