When doing web development, you often encounter the need to modify configuration information. If these configuration information is written in the code, later maintenance will be more troublesome. Therefore, the configuration information is generally written in the configuration file.
In a JSP file, if you want to invoke a variable in the properties file, you introduce the Java.util.ResourceBundle class in a file:
<%@ page contenttype= "text/html; Charset=utf-8 "import=" Java.util.ResourceBundle "%>
Known configuration file login.properties:
Login.username = Admin
Login.password [email protected]
This can be called in the page:
<%resourcebundle res = resourcebundle.getbundle ("login"); %> <% = res.getstring ("Login.username"); = Res.getstring ("Login.password"); %>
This can be called in the non-externally introduced JAVASCRITP code:
var loginName = "<%=loginname%>"; var loginpassword = "<%=loginpassword%>";
It can then be used directly from the externally introduced JavaScript code:
Alert (loginname+ ":" +loginpassword);
Note that it is not possible to use var loginName = "<%=loginname%>" in JavaScript files that are introduced externally; This is the way to assign values, because JAVASCRITP will treat <%=loginname%> as strings.