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. web应用路径问题(相对路径,绝对路径,动态获取路径)

    1.相对路径和绝对路径 绝对路径:以 “ / ” 开头的路径,是完整的路径. 相对路径:不以 “ / ” 开头的路径,是相对于当前web资源目录的路径. 在绝对路径中, “ / ” 的含义有两种解释: ...

  2. EXTJS4.2 级联 下拉

    items: [ { xtype: "fieldcontainer", layout: "hbox", items: [{ xtype: 'combo', na ...

  3. java项目 里的DAO,model,service, IMPL含义

    在一般工程中 基本上都会出现上述的字眼首先 DAO 提供了应用程序与数据库之间的操作规范 和操作 用于通常数据库的增删查改 一般如果使用框架 都是由框架自动生成,提高访问效率和便于快速开发.hiber ...

  4. 页面js框架

    js 模板,所有页面控制js,以闭包形式编写代码,降低浏览器内存消耗,加快运行速度  请按照此结构编写,便于后期前端维护和修改​1. [代码][JavaScript]代码 /** * js 模板,所有 ...

  5. Spring Boot入门——集成Mybatis

    步骤: 1.新建maven项目 2.在pom.xml文件中引入相关依赖 <!-- mysql依赖 --> <dependency> <groupId>mysql&l ...

  6. SQL Server集成服务最佳实践:语句优化

        SQL Server集成服务(SQL Server Integration Services,SSIS)在其前辈DTS(Data Transformation Services,数据转换服务) ...

  7. java/jsp: 登录系统

    db类   package db; import java.sql.*; import javax.naming.InitialContext; import javax.sql.DataSource ...

  8. Nhibernate系列学习之(五) 存储过程

    NHibernate也是能够操作存储过程的,不过第一次配置可能会碰到很多错误. 一.删除 首先,我们新建一个存储过程如下: CREATE PROC DeletePerson @Id int AS DE ...

  9. Project://Meeting_Room

    models from django.db import models from django.contrib.auth.models import AbstractUser class UserIn ...

  10. git教程5-查看关系图与no fast forward融合

    1.每一个提交相当于一个版本,版本都有版本号与之对应.通常通过git commit -m "name"为每次提交命名. 2.融合:即将次分支的最后一个版本添加到主分支上.当融合冲突 ...