[英]Accessing .env variables from an html file in a java project
I have a java project which contains an index.html
file.我有一个 java 项目,其中包含一个index.html
文件。 In this html file, I need to access an API key.在这个 html 文件中,我需要访问 API 密钥。 I store this API key in GOOGLEMAP_API_KEY
variable inside my .env
file.我将这个 API 密钥存储在我的.env
文件中的GOOGLEMAP_API_KEY
变量中。 However, I don't know how to access this GOOGLEMAP_API_KEY
variable in index.html
in my java project.但是,我不知道如何在我的 java 项目中的index.html
中访问这个GOOGLEMAP_API_KEY
变量。
My .env
file looks something like this:我的.env
文件看起来像这样:
GOOGLEMAP_API_KEY=ABCDEFGHijklmnopqrst12345
I tried to access the GOOGLEMAP_API_KEY
variable in my index.html
file with this line:我尝试使用以下行访问我的index.html
文件中的GOOGLEMAP_API_KEY
变量:
<script src="https://maps.googleapis.com/maps/api/js?key=process.env.GOOGLEMAP_API_KEY&callback=initMap"></script>
This doesn't work and I don't know how to make it work.这不起作用,我不知道如何使它起作用。 Please help.请帮忙。 Thanks in advance.提前致谢。
you can't access the .env
(environment variable) from the HTML, you need an environment or framework that she can work with him, please read more about node.js
and Django
this two environment is so popular and can work with .env
您无法从 HTML 访问.env
(环境变量),您需要一个可以与他合作的环境或框架,请阅读有关node.js
和Django
的更多信息.env
the HTML
is not a programming language it's the standard markup language for documents designed to be displayed, HTML
不是一种编程语言,它是用于显示文档的标准标记语言,
try javascript
to start developing and read more about this javascript
and node.js
can help you to read variables from .env
尝试javascript
开始开发并阅读有关此javascript
的更多信息, node.js
可以帮助您从.env
读取变量
and then please check this documentation to know how to read variables from .env
然后请查看此文档以了解如何从.env
读取变量
https://nodejs.dev/learn/how-to-read-environment-variables-from-nodejs https://nodejs.dev/learn/how-to-read-environment-variables-from-nodejs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.