Read the properties file in the JSP page

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.