国际化---demo1---bai
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的更多相关文章
- EL表达式 JSTL中的常用EL函数 动态数据的国际化
ELppt: EL 全名为Expression Language.EL主要作用: 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.( ...
- 国际化之ResourceBundle
软件在开发时要能使它同时应对世界不同地区和国家的使用,针对不同地区和国家的访问,提供相应的,符合使用者阅读习惯的操作环境,这就必须要有国际化的概念,国际化又称为“i18n”:international ...
- JavaWEB开发国际化
1.国际化开发概述 )软件的国际化:软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的.符合来访者阅读习惯的页面或数据. )国际化又称为 i18n:inter ...
- JavaWeb的国际化(17/4/8)
国际化的缺点: 因为文字不同,所以带来的排版问题一样严重,通常都是重新在写一个网站反而更加清晰,快捷 1:需要从浏览器中获取到浏览器语言(Accept-Language) 2:利用locale获取 ...
- day12 EL 表达式和国际化开发
day12 EL 表达式和国际化开发 1. EL(Expression Language) 表达式简介 1.1 执行运算 1.2 获取web开发常用对象(el 中定义了11个隐式对象) 1.3 使用 ...
- Javaweb学习笔记——(二十)——————Javaweb监听器、国际化
Javaweb监听器 三大组件 *Servlet *Listener *Filter Listener:监听器 1.初次相见:A ...
- 超全面的JavaWeb笔记day20<监听器&国际化>
JavaWeb监听器 三大组件: l Servlet l Listener l Filter Listener:监听器 1. 初次相见:AWT 2. 二次相见:SAX 监听器: l 它是一个接口,内容 ...
- Day20 javaWeb监听器和国际化
day20 JavaWeb监听器 三大组件: Servlet Listener Filter Listener:监听器 初次相见:AWT 二次相见:SAX 监听器: 它是一个接口,内容由我们来 ...
- JavaWeb开发——软件国际化(动态元素国际化)
软件国际化的第二个部分,就是动态元素国际化. 数值,货币,时间,日期等数据由于可能在程序运行时动态产生,所以无法像文字一样简单地将它们从应用程序中分离出来,而是需要特殊处理.Java 中提供了解决这些 ...
- JavaWeb开发——软件国际化(文本元素国际化)
前几天围绕着JDBC编程进行了系统的学习.现在我们对Java程序数据库操作已经是轻车熟路了.也学会了使用各种框架来帮助我们简化编程. 今天是学习计划的第七天,虽然学习热情没有前几天高涨了.但是,写博客 ...
随机推荐
- spark学习5(hbase集群搭建)
第一步:Hbase安装 hadoop,zookeeper前面都安装好了 将hbase-1.1.3-bin.tar.gz上传到/usr/HBase目录下 [root@spark1 HBase]# chm ...
- Spring初学之注解方式配置bean
直接看代码: UserController.java package spring.beans.annotation.controller; import org.springframework.be ...
- java读取Oracle的BFile文件
/** * * @author Jasmine */public class GetBlob{ public static void main(String[] args) { Connection ...
- tensorflow笔记:多层CNN代码分析
tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...
- spring: 创建环绕通知
package ch2.test; public interface Performance { void perform(); } package ch2.test; import org.aspe ...
- LightOJ - 1104 概率
题意:每年n天,求最少几个人使这些人中最少两个人生日相同的概率大于0.5 题解:直接递推,假设有k个人,所有情况为n^k,没有相同的情况为n*(n-1)*...*(n-k+1),可以算出1e5以内不超 ...
- Ubuntu下使用tmux实现分屏,以及tmux快捷键
最近用到了终端的复用,使用了tmux,写一下自己的使用和一些快捷键. tmux是指通过一个终端登录远程主机并运行后,在其中可以开启多个控制台的终端复用软件. 来个效果图: 截图我使用的命令是 gno ...
- es6语法入门let 和 const 命令
let块级作用域 { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b for循环的计数器,就很合适使用let命令(防 ...
- Spring_总结_03_装配Bean(一)_自动装配
一.前言 本文承接上一节:Spring_总结_02_依赖注入 在上一节我们了解到依赖注入的实质就是装配. 这一节我们来学习下装配Bean的相关知识. 二.Bean的装配机制 1.三种装配机制 Spri ...
- Java 面向对象编程 tricks
方法中描述了参数: 1. 构造器重载 重载构造器时,使用描述了参数的静态工厂方法名,这样做的意义何在呢?就在于为动作赋予意义,提升代码的可解释性: 传统的实例化方式: Complex fulcrumP ...