欢迎光临
我们一直在努力

About Struts—(一)-JSP教程,面向对象/设计

建站超值云服务器,限时71元/月
3. building view components
3.1 overview
本章重点描述使用jsp技术构建应用程序的view 组件。特别的, struts 不仅提供了对交互式输入表单的支持,而且提供了构建国际化应用程序的支持。几个其他相关的主题也将被简要讨论。
3.2 internationalized messages
几年前,应用程序开发者可能仅仅提供对他们自己国家用户(可能只有一种语言,有时两种)的支持,表示日期,数值以及货币的格式是单一的。然而,基于web技术的应用发展,在许多情况下,国界已经变得模糊不清。支持国际化(internationalization) 和本地化(localization)变得很重要。 struts 构建在java 平台之上,提供了构建国际化和本地化应用程序的帮助。主要内容有: · locale – 支持国际化的基本的java class是java.util.locale。每一个 locale 代表一个特定的国家和语言(加上一个可选的语言变量)的选择,和一组假定的数值和日期的格式。 · resourcebundle – java.util.resourcebundle 类是支持多语消息的基本工具类。参见resourcebundle 类的javadocs 。 · propertyresourcebundle – resourcebundle的一个标准实现,它允许你使用"name=value"的语法定义资源。这对于文本资源来说非常方便。 · messageformat – java.text.messageformat 类允许你在运行时使用参数替代message string 中的一部分。the placeholder string {0} in the message is replaced by the first runtime argument, {1} is replaced by the second argument, and so on. · messageresourcesorg.apache.struts.util.messageresources 类使你像对待数据库一样处理一组资源,并允许你request a particular message string for a particular locale (normally one associated with the current user) instead of for the default locale the server itself is running in. 请注意the i18n support in a framework like struts is limited to the presentation of internationalized text and images to the user. support for locale specific input methods (used with languages such as japanese, chinese, and korean) is left up to the client device, which is usually a web browser. 对于一个国际化的应用程序,follow the steps described in the internationalization document in the jdk documentation bundle for your platform to create a properties file containing the messages for each language. an example will illustrate this further: 假定你的源代码创建在package com.mycompany.mypackage, 所以它被存储在一个名叫com/mycompany/mypackage的目录中 。创建一个叫作com.mycompany.mypackage.myresources的资源包,你将在目录com/mycompany/mypackage 下创建下列文件: · myresources.properties – 包含了你的服务器的缺省语言资源。如果你的缺省语言是英语,可能会是这个样子:prompt.hello=hello · myresources_xx.properties – 包含了同样的资源,它们的iso 语言代码是"xx" (参见resourcebundle javadoc)。对于一个法语的版本,可能会是这样:prompt.hello=bonjour ,你可以创建你需要的任意多个资源包。当你在web application deployment descriptor中配置controller servlet时,你需要定义的一个初始化参数是应用程序使用的资源包名称。在上面的例子中,将会是com.mycompany.mypackage.myresources.


  action
  org.apache.struts.action.actionservlet
  
    application
    com.mycompany.mypackage.myresources
  
  <.../>

资源包应该放置在class path中。另一种方式是将myresources.properties 文件保存在应用程序的classes 文件夹内。那么,你可以简单的在你的应用程序中使用"myresources"。 just be careful it is not deleted if your build script deletes classes as part of a "clean" target. if it does, here is an ant task to run when compiling your application that copies the contents of a src/conf directory to the classes directory:

        
        
            
        
       
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » About Struts—(一)-JSP教程,面向对象/设计
分享到: 更多 (0)

相关推荐

  • 暂无文章