JSP多语言第一种
来源:互联网 发布:ehviewer 网络错误 编辑:程序博客网 时间:2024/06/07 23:09
以jsp页面title举例:
读取多语言肯定要放在properties中,并且通过后台读取properties对应的键返回其值,则jsp页面需要引入类:
<%@page import="com.mytest.sys.config.SysTextConfig"%>这里SysTextConfig类处理多语言
<title><%=SysTextConfig.getConfigInfo("bsd_text")+SysTextConfig.getConfigInfo("title")%></title>
SysTextConfig类的内容为
public class SysTextConfig { private static Properties properties =null;//读取properties的资源文件private static long lastModified=0;//内存中上次修改的时间 long型 private static String filePath=null;//保存properties文件的绝对路径 private static File sysConfigFile=null; static {//初始化static变量的值 StringBuffer configFilePath = new StringBuffer(); String classPath= SysTextConfig.class.getClassLoader().getResource("").getPath(); String weninfoPath = classPath.substring(0,classPath.lastIndexOf("classes")); configFilePath.append(weninfoPath).append("config");configFilePath.append(File.separator).append("sysText.properties");filePath=configFilePath.toString(); } private static boolean isNotlastModified(){ sysConfigFile= new File(filePath); if( sysConfigFile.lastModified()!=lastModified) return true; return false; } private static void loadSysConfigFile(){ properties = new Properties(); FileInputStream fileInputStream; try {fileInputStream = new FileInputStream(sysConfigFile);properties.load(fileInputStream);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} } public static String getConfigInfo(String key) { //函数入口,首先校验properties文件的最近以次修改时间,如果不为0 则代表其修改过 则要再次加载loadSysConfigFile if(isNotlastModified()) loadSysConfigFile(); Object object = properties.get(key); //读取properties的键 String value =""; try { if(StringUtils.isNotEmpty(object)){ value = new String(object.toString().getBytes("ISO8859_1"));//通过键返回其值 }} catch (UnsupportedEncodingException e) {e.printStackTrace();} return value; } }
- JSP多语言第一种
- JSP多语言第一种
- struts2映射jsp页面的第一种方法
- C#开发第一天-选择一种开发语言
- 实现web多语言的一种解决办法
- 实现web多语言的一种解决办法
- JSP的一种分页
- JSP入门——第2章 HTML语言
- javaCV 配置第一种
- 命名规则(第一种)
- 第一种类型界面
- c语言 习题5.8参考答案(第一种解法,用if~else~语句)
- 通用线程:awk 实例,第 1 部分:一种名称很奇特的优秀语言介绍
- 【C语言提高24】二级指针做输入的第一种内存模型:数组指针
- 5、第2篇 JSP语言基础之----JSP基本语法
- 共用一种语言说话
- 如何添加一种语言?
- 如何添加一种语言?
- RTP协议分析(转载)
- Javascript鼠标事件大全
- 虚拟服务器的路由端口映射
- Windows 2008安装Oracle10g提示操作系统版本检查未通过
- 使用HttpCore(HttpComponents)在android上构建webService
- JSP多语言第一种
- 严重: Exception starting filter struts2urce' to 'org.
- Oracle 排序 使用 nulls first 或者 nulls last
- WINCE下进程间通信(一)
- power vm实战
- utf8中文编码范围
- GCM入门
- Java中的finalize详解
- android新手总结