web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

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.dtd">
<struts>
  <constant name="struts.custom.i18n.resources" value="app" />
  <package name="default" namespace="/" extends="struts-default">
    <action name="firstAction" class="com.huawei.s2.action.FirstAction" >
      <result name="success" >/ok.jsp</result>
    </action>
  </package>
</struts>

src下的配置文件

app_en_US.properties:

welcome.msg=welcome to beijing

app_zh_CN.properties:

welcome.msg=\u5317\u4EAC\u6B22\u8FCE\u4F60

action:

import com.opensymphony.xwork2.ActionSupport;
//ActionSupport:资源国际化及表单验证类
public class FirstAction extends ActionSupport{
  public String execute(){
    String str = getText("welcome.msg");//会根据浏览器设置的语言来读取相应的信息
    System.out.println(str+"============================");
    return "success";
  }
}

jsp:

1.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>struts2资源国际化</title>
  </head>
  <body>
    <form action="firstAction">
      <input name="uname" value="zhangsan" /><br/>
      <input type="submit" value="提交" />
    </form>
  </body>
</html>

ok.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'ok.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
  </head>
  <body>
    <h1>提交成功</h1>
  </body>
</html>

struts2 资源国际化的更多相关文章

  1. Struts2【UI标签、数据回显、资源国际化】

    Struts2UI标签 Sturts2为了简化我们的开发,也为我们提供了UI标签...也就是显示页面的标签..... 但是呢,Struts2是服务端的框架,因此使用页面的标签是需要在服务器端解析然后再 ...

  2. Struts2 资源配置文件国际化

    Struts2 资源配置文件国际化 Struts2资源文件的命名规范:basename_language_country.properties Struts2国际化如果系统同时存在资源文件.类文件,系 ...

  3. 十四、Struts2的国际化

    十四.Struts2的国际化 1.配置全局国际化消息资源包 配置全局消息资源包 <!--配置全局消息资源包 -->     <constant name="struts.c ...

  4. Struts第八篇【资源国际化、对比JSP的资源国际化】

    资源国际化 我们在学JSTL标签的时候就涉及到了资源国际化,,,但是呢,在JSP的章节我并没有写博文来讲解怎么弄-.一方面感觉JSP的资源国际化好麻烦,另一方面是感觉用的地方很少-..因此就没有深入去 ...

  5. JavaWeb框架_Struts2_(八)----->Struts2的国际化

    这一篇博文拖了蛮久了,现在先把它完成,结束struts2这个版块,当然这只是最基础的部分,做项目还需要更深的理解.下一个web后端的版块准备做Spring框架的学习-嗯,加油! 1. Struts2的 ...

  6. struts2使用拦截器完成登陆显示用户信息操作和Struts2的国际化

    其实学习框架,就是为了可以很好的很快的完成我们的需求,而学习struts2只是为了替代之前用的servlet这一层,框架使开发更加简单,所以作为一个小菜鸟,特别感谢那些超级无敌变态开发的框架供我们使用 ...

  7. Struts2的国际化入门

    Struts2的国际化入门 Struts2国际化是建立在Java国际化的基础上的,一样是通过提供不同国家/语言环境的消息资源,然后通过ResourceBundle加载指定Locale对应的资源文件,再 ...

  8. 浅谈struts2的国际化----i18n

    可能大家在使用struts框架的时候,偶尔会看到这个词: i18n.也就是 Internationalization    i 开头,n 结尾. 总共18个字母,今天的主要内容就是环绕这 四个字母. ...

  9. 【Struts2】 国际化

    一.概述 二.Struts2中国际化: 2.1 问题1 全局 局部 2.2 问题2 2.3 问题3 2.4 问题4 在Action中怎样使用 在JSP页面上怎样使用 一.概述 同一款软件 可以为不同用 ...

随机推荐

  1. Centos替换默认源

    将默认的国外源替换为国内的网易的源 参考帮助文档:http://mirrors.163.com/.help/centos.html 查看本机版本:cat /etc/redhat-release 先安装 ...

  2. php 生成.csv的文件

    $data = array( "title" => array("服务器", "链接", "对应ID"), &qu ...

  3. 峰Spring4学习(4)spring自动装配

    一.自动装配: Model类: People.java: package com.cy.entity; public class People { private int id; private St ...

  4. linux 查看文件夹下的文件个数(当前目录的文件数)//包含子目录

    ls -l |grep "^-"|wc -l   //验证了redhat好用 或 find ./company -type f | wc -l 查看某文件夹下文件的个数,包括子文件 ...

  5. Python单例模式的4种实现方法

    #-*- encoding=utf-8 -*- print '----------------------方法1--------------------------' #方法1,实现__new__方法 ...

  6. python 模块被引用多次但是里面的全局表达式总共只会执行一次

    python 模块被引用多次但是里面的全局表达式总共只会执行一次

  7. Thread 1 cannot allocate new log的问题分析 (转载)

    Thread 1 cannot allocate new log的问题分析 发生oracle宕机事故,alert文件中报告如下错误: Fri Jan 12 04:07:49 2007Thread 1 ...

  8. PyQt5系列教程(九)QInputDialog的使用

    软硬件环境 Ubuntu 15.10 32bit Python 3.5.1 PyQt 5.5.1 前言 输入框是界面开发中非常常见的控件,本文就来看看PyQt5中QInputDialog的使用 实例 ...

  9. uva-167-枚举

    题意:八皇后问题,要求选取的总和最大 #include<stdio.h> #include<iostream> #include<sstream> #include ...

  10. OpenCL 双调排序 CPU 版

    ▶ 学习了双调排序,参考(https://blog.csdn.net/xbinworld/article/details/76408595) ● 使用 CPU 排序的代码 #include <s ...