zoukankan      html  css  js  c++  java
  • struts2的国际化文件在jsp中的引用

    struts.xml中的配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            "http://struts.apache.org/dtds/struts-2.0.dtd">
    
    <struts>
    	<constant name="struts.custom.i18n.resources" value="mess"></constant>
    	<package name="default" extends="struts-default">
    		<action name="login" class="com.action.LoginAction">
    			<result name="success">index.jsp</result>
    		</action>
    	</package>
    </struts>
    

     jsp中的代码

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    	<s:textfield name="username" key = "username"></s:textfield>
    	<s:text name="username"></s:text>	
    </body>
    </html>
    

     然后配置一个基类的mess.properties,然后中文配置在mess_zh_CN.properties,英文配置在mess_en_US.properties中。这里的规则就是基类名mess_语言_国家.properties

    效果如下:

    浏览器的优先语言为英语的时候:

    浏览器语言为中文的时候显示为:

  • 相关阅读:
    ASP.NET MVC学习笔记-----ActionInvoker
    quartz启动报错
    THUSC 2021 游记
    C++下随机数的生成
    友链
    memset一些技巧
    CodeForces Round #705 总结&题解
    php计算两坐标距离
    vue中使用keepAlive组件缓存遇到的坑
    vue 中 keepAlive
  • 原文地址:https://www.cnblogs.com/hongcong/p/6037656.html
Copyright © 2011-2022 走看看