login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
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 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<s:text name="tip"/><br/>
<s:form action="login.action">
<s:textfield key="username" name="username"/><br/>
<s:password key="password" name="password"/><br/>
<s:submit key="submit"/>
<s:reset key="reset"/>
</s:form><br/> <a href="tochn.action"><s:text name="tochn"/></a>
<a href="toeng.action"><s:text name="toeng"/></a> </body>
</html>

  

welcome.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
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 'welcome.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
<s:text name="sucinfo"/>
</body>
</html>

  

error.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
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 'welcome.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
<s:text name="failinfo"/>
</body>
</html>

  

LoginAction

package com.etc.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport
{
private String username;
private String password; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String execute()
{
//java代码中的国际化
System.out.println(this.getText("username"));
if("123".equals(password)&&"admin".equals(username))
return "success";
return "fail";
}
}

  

LanguageAction

package com.etc.action;

import java.util.Locale;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class LanguageAction extends ActionSupport
{
//转化成中文
public String tochn()
{
Locale loc = new Locale("zh","CN");
//修改当前action上下文的语言配置
ActionContext.getContext().setLocale(loc); //通过session配置,让新的语言对本会话生效
ServletActionContext.getRequest().getSession()
.setAttribute("WW_TRANS_I18N_LOCALE",loc);
return "success";
}
//转化成英文
public String toeng()
{
Locale loc = new Locale("en","US");
//修改当前action上下文的语言配置
ActionContext.getContext().setLocale(loc); //通过session配置,让新的语言对本会话生效
ServletActionContext.getRequest().getSession()
.setAttribute("WW_TRANS_I18N_LOCALE",loc);
return "success"; }
}

  

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="mess"/>
<constant name="struts.devMode" value="true"/>
<package name="p" extends="struts-default" namespace="/">
<action name="login" class="com.etc.action.LoginAction">
<result name="success">
/welcome.jsp
</result>
<result name="fail">
/error.jsp
</result>
</action>
<action name="*" class="com.etc.action.LanguageAction" method="{1}">
<result>
/login.jsp
</result>
</action>
</package>
</struts>

  

mess_en_US.properties    英文文件              文件命名一定要注意:xxx_en_US.properties

tip=Please input your name and password
username=User Name
password=Your password
submit=Login
reset=Reset
sucinfo=Login ok.You are Welcome.
failinfo=Login fail.
tochn=Chinese Ver.
toeng=English Ver.

  

mess_zh_CN.properties       中文文件

tip=\u8BF7\u8F93\u5165\u7528\u6237\u540D\u548C\u5BC6\u7801
username=\u7528\u6237\u540D
password=\u5BC6\u7801
submit=\u767B\u5F55
reset=\u91CD\u7F6E
sucinfo=\u767B\u5F55\u6210\u529F\uFF01\u6B22\u8FCE\u4F7F\u7528\u3002
failinfo=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
tochn=\u4E2D\u6587\u7248
toeng=\u82F1\u6587\u7248

  

国际化---demo1---bai的更多相关文章

  1. EL表达式 JSTL中的常用EL函数 动态数据的国际化

    ELppt: EL 全名为Expression Language.EL主要作用: 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.( ...

  2. 国际化之ResourceBundle

    软件在开发时要能使它同时应对世界不同地区和国家的使用,针对不同地区和国家的访问,提供相应的,符合使用者阅读习惯的操作环境,这就必须要有国际化的概念,国际化又称为“i18n”:international ...

  3. JavaWEB开发国际化

    1.国际化开发概述 )软件的国际化:软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的.符合来访者阅读习惯的页面或数据. )国际化又称为 i18n:inter ...

  4. JavaWeb的国际化(17/4/8)

      国际化的缺点: 因为文字不同,所以带来的排版问题一样严重,通常都是重新在写一个网站反而更加清晰,快捷 1:需要从浏览器中获取到浏览器语言(Accept-Language) 2:利用locale获取 ...

  5. day12 EL 表达式和国际化开发

    day12 EL 表达式和国际化开发 1. EL(Expression Language) 表达式简介 1.1 执行运算 1.2 获取web开发常用对象(el 中定义了11个隐式对象) 1.3 使用 ...

  6. Javaweb学习笔记——(二十)——————Javaweb监听器、国际化

    Javaweb监听器     三大组件         *Servlet         *Listener         *Filter Listener:监听器         1.初次相见:A ...

  7. 超全面的JavaWeb笔记day20<监听器&国际化>

    JavaWeb监听器 三大组件: l Servlet l Listener l Filter Listener:监听器 1. 初次相见:AWT 2. 二次相见:SAX 监听器: l 它是一个接口,内容 ...

  8. Day20 javaWeb监听器和国际化

    day20 JavaWeb监听器 三大组件: Servlet Listener Filter   Listener:监听器 初次相见:AWT 二次相见:SAX   监听器: 它是一个接口,内容由我们来 ...

  9. JavaWeb开发——软件国际化(动态元素国际化)

    软件国际化的第二个部分,就是动态元素国际化. 数值,货币,时间,日期等数据由于可能在程序运行时动态产生,所以无法像文字一样简单地将它们从应用程序中分离出来,而是需要特殊处理.Java 中提供了解决这些 ...

  10. JavaWeb开发——软件国际化(文本元素国际化)

    前几天围绕着JDBC编程进行了系统的学习.现在我们对Java程序数据库操作已经是轻车熟路了.也学会了使用各种框架来帮助我们简化编程. 今天是学习计划的第七天,虽然学习热情没有前几天高涨了.但是,写博客 ...

随机推荐

  1. 去除带有iframe页面中的2个滚动条[转]

    方法一:加载frame时修改高度 <div>    <iframe id="frame_content" name="frame_content&quo ...

  2. 关于发邮件报错535 Error:authentication failed&553 authentication is required

    553 authentication is required:这个错误的意思是你必须需要认证. 也就是说,你连接smtp服务器的时候必须使用密码来连接:下面代码红色那句 代码: @Override p ...

  3. vs+mysql+ef配置方法

    这次的项目用的是MySQL数据库,但是ADO.NET实体数据模型默认是不支持MySQL数据库的,本文档将介绍如何让VS ADO.NET实体数据模型支持MySQL. 一.安装插件 1.VS插件 mysq ...

  4. 基于docker环境,搭建 jetty环境, 部署java项目

    前提: 1.Ubuntu 系统. 2.docker环境已经安装好. 实现步骤: 1.上docker hub 下载jetty docker 镜像. 执行命令:$ sudo docker pull jet ...

  5. Oracle通过PLSQL进行数据表之间的同步

    昨天被要求拉取第三方oracle中的一个表数据,起初以为要导出表数据,然后再自己库中建个相同的表,然后导入数据,查过资料之后oracle可以通过dblink的方式同步表数据. 1.首先利用PLSQL工 ...

  6. review28

    前面介绍了指向文件的输入流和输出流.随机流是既能读文件也能写文件. RandomAccessFile类创建的流称做随机流,与前面的输入.输出流不同的是,RandomAccessFile类既不是Inpu ...

  7. underscore中template的使用Demo

    在客户端渲染数据时,一般可通过underscore中的template对数据模板进行渲染,例如: 定义模板,需要把type类型设置为“text/template” <script type=&q ...

  8. array_merge函数的注意事项

    array_merge — 合并一个或多个数组 array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面.返回作为结果的数组 如果输入的数组中有相同的字符串键名 ...

  9. 《Advanced Bash-scripting Guide》学习(十五):测试坏的链接文件(broken link)

    本文所选的例子来自于<Advanced Bash-scripting Gudie>一书,译者 杨春敏 黄毅 #/bin/bash #用一个纯粹的shell脚本来找出坏链接文件 #什么是br ...

  10. 完全分布式安装hadoop集群

    0.安装jdk 1.配置hosts文件 2.建立hadoop运行账号 3.配置ssh免密码登录 4.在namenode上配置hadoop 4.1.修改hadoop-env.sh文件 4.2.修改yar ...