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. MapReduce-计数器

    计数器 计数器是收集作业统计信息的有效手段之一,用于质量控制或应用级统计.计数器还可辅助诊断系统故障.根据计数器值来记录某一特定事件的发生比分析一堆日志文件容易得多.内置计数器Hadoop为每个作业维 ...

  2. HDFS-文件写入API

    package com.zhen.hdfs; import java.io.BufferedInputStream; import java.io.FileInputStream; import ja ...

  3. Kafka详解四:Kafka的设计思想、理念

    问题导读 1.Kafka的设计基本思想是什么?2.Kafka消息转运过程中是如何确保消息的可靠性的? 本节主要从整体角度介绍Kafka的设计思想,其中的每个理念都可以深入研究,以后我可能会发专题文章做 ...

  4. ZSTU 4241 圣杯战争(线段树+经典)

    题意:CS召唤了n个实验怪兽,第i号怪兽在i这个位置出.并把KI召唤出的第i位从者安排在pos(i)处,总共有m位从者. 第i只怪兽有战斗力atk(i), 而i号从者的体力为AP(i).如果从者想要移 ...

  5. session共享个人小结

    一.需求问题: 如果你的网站是存放在一个机器上,那么是不存在这个问题的,因为会话数据就在这台机器,但是如果你使用了负载均衡把请求分发到不同的机器呢? 这个时候会话id在客户端是没有问题的, 但是如果用 ...

  6. Guest CPU model configuration in libvirt with QEMU/KVM

    每个hypervisor对于guest能看到的cpu model定义都不同,Xen 提供host pass through,所以guest能看到的cpu和host完全相同. QEMU/KVM中gues ...

  7. 碰到错误Could not load the Tomcat server configuration at \Servers\MyEclipse Tomcat v8.5-config. The Servers project is closed.

    本人用的myeclipse是2017版. 可能解决的方法是: 双击MyEclipse Tomcat v8.5,然后就会弹出以下窗口,

  8. PHP error_get_last() 函数

    error_get_last() 函数返回最后发生的错误 返回了一个关联数组,描述了最后错误的信息,以该错误的 "type". "message"." ...

  9. 使用JMeter建立接口测试

    [需求]某组机器是Android和iOS输入法接口服务器,有很多重要的接口,例如:升级,网络开关,热词等.现在有3台机器过保要下线,新申请了3台机器,需要验证一下这3台机器接口的正确性. [测试步骤] ...

  10. poj2114树分治

    题意:给你一棵树,每条边有权值,求有没有一条链使得权值和为k 题解:和上一题类似,依旧是树分治,只是我们储存结果的时候是判断加起来为k的点对数,刚开始本来想用map存答案,结果就t了,后来用了vect ...