jsp配置文件数据信息读取

一、jsp从配置文件*.properties读取信息

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
    ResourceBundle resource = ResourceBundle.getBundle("config"); <!--配置文件名-->

    String logoPath =ctx + resource.getString("System_Logo");
    request.setAttribute("logoPath", logoPath);

%>
<title>
<!-- 直接输出配置值 -->
<%=resource.getString("System_Name") %>
<!-- 由于properties配置文件默认的编码为:ISO-8859-1,是不支持中文的,会乱码 -->
<%=new String(resource.getString("System_Name").getBytes("ISO-8859-1"), "UTF8") %>
</title>

<body>
    <script type="text/javascript">
        // 赋值给js变量
        var systemName ='resource.getString("System_Name")';
      或
     '${logoPath }'
</script> </body>

import属性用于导入java中的包,import属性可以指定多个值,这些值之间需要用逗号(,)进行分隔。

表示 java.util包 中的所有类在使用时无需给出明确的包标识符。

jsp中import 是 page 的属性中惟一允许在同一文档中多次出现的属性。尽管 page 指令可以出现在文档中的任何地方,但一般不是将 import 语句放在文档顶部附近,就是放在相应的包首次使用之前。

java:

通过 java.util.ResourceBundle 类来读取,这种方式比使用 Properties 要方便一些

  1>通过 ResourceBundle.getBundle() 静态方法来获取(ResourceBundle是一个抽象类),这种方式来获取properties属性文件不需要加.properties后缀名,只需要文件名即可

public static ResourceBundle resource = ResourceBundle.getBundle("config");
public static String system_Type_Config = resource.getString("System_Type");

 EL表达式:

<%  request.setAttribute("logoPath", logoPath);  %>  //设置值

${logoPath}  //取值

原文地址:https://www.cnblogs.com/lijianda/p/8759407.html