jsp/js读取properties文件的方法
2013-07-10 09:05
405 查看
jsp中读取properties文件,并把值设到js变量中:
web_stderr.properties文件内容:
[xhtml]
view plaincopy
common.username.error.null = UserName can not be null.
common.username.error.invalid = UserName is invalid.
common.password.error.null = Password can not bu null.
common.password.error.invalid = Password is invalid.
common.login.error.user = The user can not been stored or password is wrong.
common.request.parameter.error = Request parameter error.
common.function.title.null = The tilte of function or is null.
common.session.timeout = The session has already expired.Please login again.
1.存储properties文件内容的js变量(common-checkmessage.jsp):
[xhtml]
view plaincopy
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.ResourceBundle"%>
<!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></title>
<%ResourceBundle res = ResourceBundle.getBundle("web_stderr"); %>
<mce:script type="text/javascript"><!--
var check_message_username_null = '<%=res.getString("common.username.error.null")%>';
var check_message_username_invalid = '<%=res.getString("common.username.error.invalid")%>';
var check_message_password_null = '<%=res.getString("common.password.error.null")%>';
var check_message_password_invalid = '<%=res.getString("common.password.error.invalid")%>';
// --></mce:script>
</head>
<body>
</body>
</html>
此时只要在其他jsp中包含该jsp文件,就可以在jsp和js文件中使用这些变量。
web_stderr.properties文件内容:
[xhtml]
view plaincopy
common.username.error.null = UserName can not be null.
common.username.error.invalid = UserName is invalid.
common.password.error.null = Password can not bu null.
common.password.error.invalid = Password is invalid.
common.login.error.user = The user can not been stored or password is wrong.
common.request.parameter.error = Request parameter error.
common.function.title.null = The tilte of function or is null.
common.session.timeout = The session has already expired.Please login again.
1.存储properties文件内容的js变量(common-checkmessage.jsp):
[xhtml]
view plaincopy
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.ResourceBundle"%>
<!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></title>
<%ResourceBundle res = ResourceBundle.getBundle("web_stderr"); %>
<mce:script type="text/javascript"><!--
var check_message_username_null = '<%=res.getString("common.username.error.null")%>';
var check_message_username_invalid = '<%=res.getString("common.username.error.invalid")%>';
var check_message_password_null = '<%=res.getString("common.password.error.null")%>';
var check_message_password_invalid = '<%=res.getString("common.password.error.invalid")%>';
// --></mce:script>
</head>
<body>
</body>
</html>
此时只要在其他jsp中包含该jsp文件,就可以在jsp和js文件中使用这些变量。
相关文章推荐
- jsp中读取properties文件 (jsp中读取properties文件,并把值设到js变量中)
- java读取properties配置文件的方法
- J2SE API读取Properties文件六种方法
- JS读取XML文件数据并以table形式显示数据的方法(兼容IE与火狐)
- JS读取本地文件及目录的方法
- 使用J2SE API读取Properties文件的六种方法
- JS通过ajax动态读取xml文件内容的方法
- Java读取Properties文件的六种方法
- JSP中,防止 css js img 等文件的缓存的方法
- Java读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法
- Java读取Properties文件的六种方法
- Java读取Properties文件的六种方法
- java各种读取properties文件方法
- 使用J2SE API读取Properties文件的六种方法
- ResourceBundle (读取properties文件及中文乱码解决方法)
- java读取Properties文件六种方法
- 简单读取Properties文件的方法
- java读取properties资源文件的六种方法
- Java读取properties配置文件常用方法