1、配置web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  3. <display-name>springmvc_fileupload</display-name>
  4. <welcome-file-list>
  5. <welcome-file>index.html</welcome-file>
  6. <welcome-file>index.htm</welcome-file>
  7. <welcome-file>index.jsp</welcome-file>
  8. <welcome-file>default.html</welcome-file>
  9. <welcome-file>default.htm</welcome-file>
  10. <welcome-file>default.jsp</welcome-file>
  11. </welcome-file-list>
  12.  
  13. <!-- <listener>
  14. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  15. </listener> -->
  16.  
  17. <filter>
  18. <filter-name>encodingFilter</filter-name>
  19. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  20. <init-param>
  21. <param-name>encoding</param-name>
  22. <param-value>UTF-8</param-value>
  23. </init-param>
  24. </filter>
  25. <filter-mapping>
  26. <filter-name>encodingFilter</filter-name>
  27. <url-pattern>/*</url-pattern>
  28. </filter-mapping>
  29.  
  30. <servlet>
  31. <servlet-name>springmvc</servlet-name>
  32. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  33. <init-param>
  34. <param-name>contextConfigLocation</param-name>
  35. <param-value>classpath:springmvc-servlet.xml</param-value>
  36. </init-param>
  37. <load-on-startup>1</load-on-startup>
  38. </servlet>
  39. <servlet-mapping>
  40. <servlet-name>springmvc</servlet-name>
  41. <url-pattern>*.action</url-pattern>
  42. </servlet-mapping>
  43.  
  44. </web-app>

2、配置springmvc-servlet.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xmlns:context="http://www.springframework.org/schema/context"
  9. xmlns:c="http://www.springframework.org/schema/c"
  10. xmlns:cache="http://www.springframework.org/schema/cache"
  11. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  12. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
  13. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  14. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  15. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  16. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
  17.  
  18. <context:component-scan base-package="com.wh.handler"></context:component-scan>
  19.  
  20. <context:annotation-config /> <!--激活Bean中定义的注解 -->
  21. <mvc:annotation-driven />
  22.  
  23. <!-- 配置国际化文件 -->
  24. <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
  25. <!-- 国际化信息所在的文件名 -->
  26. <property name="basename" value="messages" />
  27. <!-- 如果在国际化资源文件中找不到对应代码的信息,就用这个代码作为名称 -->
  28. <property name="useCodeAsDefaultMessage" value="true" />
  29. </bean>
  30.  
  31. </beans>

3、编写index.jsp

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  6. %>
  7.  
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  9. <html>
  10. <head>
  11. <base href="<%=basePath%>">
  12.  
  13. <title>My JSP 'index.jsp' starting page</title>
  14. <meta http-equiv="pragma" content="no-cache">
  15. <meta http-equiv="cache-control" content="no-cache">
  16. <meta http-equiv="expires" content="0">
  17. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18. <meta http-equiv="description" content="This is my page">
  19. </head>
  20. <body>
  21.  
  22. <!-- ${pageContext.request.contextPath} 这个是比较重要的,否则路径老是不对 -->
  23. <form action="${pageContext.request.contextPath}/intern.action" method="get">
  24. <input type="text" name="un" value="xxx"/> <br/>
  25. <input type="submit" value="提交"/> <br/>
  26. </form>
  27.  
  28. </body>
  29. </html>

4、编写handler.java

  1. package com.wh.handler;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4.  
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.servlet.support.RequestContext;
  8.  
  9. @Controller
  10. public class InternationHandler {
  11.  
  12. @RequestMapping("intern.action")
  13. public String demo(HttpServletRequest request){
  14. System.out.print("后台国际化:");
  15. //后台代码中通过RequestContext对象的getMessage方法获取国际化信息
  16. RequestContext requestContext = new RequestContext(request);
  17. String msg = requestContext.getMessage("uname");
  18. System.out.println("msg:"+msg);
  19. return "hello.jsp";
  20. }
  21. }

5、编写hello.jsp

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  4. <html>
  5. <head>
  6. <title>My JSP 'index.jsp' starting page</title>
  7. </head>
  8. <body>
  9. <!-- 浏览器问题,有的浏览器不支持国际化,比如360浏览器 -->
  10. 前端国际化 <br>
  11. <spring:message code="uname"></spring:message>
  12. </body>
  13. </html>

6、配置国际化文件

messages_zh_CN.properties、messages_en_US.properties、messages_ja_JP.properties、messages.properties

注意:要先从index页面,经过后台处理,再到前台hello页面才行,同时,要注意浏览器问题,一个浏览器不支持国际化,试试其他浏览器。 

国际化------international的更多相关文章

  1. Hello Web API系列教程——Web API与国际化

    软件国际化是在软件设计和文档开发过程中,使得功能和代码设计能处理多种语言和文化习俗,在创建不同语言版本时,不需要重新设计源程序代码的软件工程方法.这在很多成熟的软件开发平台中非常常见.对于.net开发 ...

  2. Web API与国际化

    软件国际化是在软件设计和文档开发过程中,使得功能和代码设计能处理多种语言和文化习俗,在创建不同语言版本时,不需要重新设计源程序代码的软件工程方法.这在很多成熟的软件开发平台中非常常见.对于.net开发 ...

  3. C# 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母

    首先下载Visual Studio International Pack 1.0,官方下载地址:http://www.microsoft.com/downloads/zh-cn/details.asp ...

  4. Microsoft Visual Studio International Pack 1.0 SR1--关于汉字转拼音

    Microsoft Visual Studio International Pack 1.0 SR1————微软的一个类库 地址:http://www.microsoft.com/zh-cn/down ...

  5. iOS应用国际化教程(2014版)

    本文转载至 http://www.cocoachina.com/industry/20140526/8554.html 这篇教程将通过一款名为iLikeIt的应用带你了解最基础的国际化概念,并为你的应 ...

  6. iOS APP 国际化

    pp Store 中很多流行的应用程序有多种语言版本.虽然这些应用程序可能因为很多因素而变得流行,但是具有多种本地化版本,肯定是其中一个因素.越多的人可以理解并使用您的应用程序,潜在的买家也就越多. ...

  7. iOS应用国际化教程

    开发一款伟大的iOS应用程序是件了不起的事情,但是还有比优秀的代码.华丽的设计以及直观化交互更多的事要做.跻身在App Store排行榜前列还需要正合时宜的产品营销.扩大用户群的能力.实用的工具以及尽 ...

  8. 初识ABP vNext(6):vue+ABP实现国际化

    Tips:本篇已加入系列文章阅读目录,可点击查看更多相关文章. 目录 前言 开始 语言选项 语言切换 注意 最后 前言 上一篇介绍了ABP扩展实体,并且在前端部分新增了身份认证管理和租户管理的菜单,在 ...

  9. PHP中国际化的字符串比较对象

    在 PHP 中,国际化的功能非常丰富,包括很多我们可能都不知道的东西其实都非常有用,比如说今天要介绍的这一系列的字符排序和比较的功能. 排序 正常来说,如果我们对数组中的字符进行排序,按照的是字符的 ...

随机推荐

  1. 执行循环任务new Timer().schedule(new TimerTask(){},0,1000);

    package com.pingyijinren.test; import android.support.v7.app.AppCompatActivity; import android.os.Bu ...

  2. ****HTML模板资源汇总

    站长素材: http://sc.chinaz.com/tag_moban/HTML.html wordpress模板: http://www.cssmoban.com/wpthemes/ http:/ ...

  3. Elasticsearch5.6搭建及拼音中文混合搜索实现

    https://blog.csdn.net/UUfFO/article/details/78154499

  4. 携程Apollo(阿波罗)配置中心把现有项目的配置文件迁移到Apollo

    说明: 1.这个示例应该算是一个静态迁移,也就是说配置更新后要重启应用才能体现更新,目的是展示现有配置的如何迁移. 2.如果要实现更新配置后动态去更新而不重启应用的操作,比如ZK地址和数据库地址这些, ...

  5. wget: unable to resolve host address “mirrors.163.com” 的解决办法

    wget:无法解析主机地址.这就能看出是DNS解析的问题. 解决办法: 登入root(VPS). 进入/etc/resolv.conf. 修改内容为下nameserver 8.8.8.8 #googl ...

  6. JSP的会话(Session)跟踪

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/session-tracking.html: 会话(Session) HTTP是一个“无状态”协议,这意味 ...

  7. 我的arcgis培训照片8

    来自:http://www.cioiot.com/successview-554-1.html

  8. 剑指Offer —— BFS 宽度优先打印

    https://www.nowcoder.net/practice/7fe2212963db4790b57431d9ed259701?tpId=13&tqId=11175&tPage= ...

  9. debug 和release 的区别

    http://blog.csdn.net/h_wlyfw/article/details/26688677

  10. ZOJ3659 Conquer a New Region 并查集

    Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history roll ...