如何使用 Java 脚本从属性文件中读取值

How to read value from property file using Java Script?

本文关键字:读取 文件 从属性 何使用 Java 脚本      更新时间:2023-09-26

>我在速度脚本中添加了文本字段和一个按钮,该脚本通过Web应用程序使用。启动 Web 应用时,将读取 start.properties 文件。有一个属性:debug_on可以采用两个值 0 或 1。

所以我想根据debug_on值显示文本字段和按钮。如果我没记错的话,它可以通过javascript在速度脚本中完成(我不是JavaScript专家),但是我需要获取属性值才能进一步移动。

我怎样才能实现它?

更新

Velocity脚本示例,其中主要GWT(Java)代码嵌入在末尾:

<!--doctype head declaration-->
   <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Web App</title>
      <style>
        <!-- styles -->
      </style>
      <link rel="stylesheet" href="/css/webapp.css" type="text/css"/>
      <meta name='gwt:module' content='$uri'>
    </head>
    <body>
        <script language="javascript" src="/$uri/com.myproject.gwt.main.nocache.js"></script>
        <!-- TextField and button are located here -->
        <table style="width: 300px; height: 100px;" class="gwt-DialogBox" cellpadding="0" cellspacing="5">
            <!-- some other part of a page tha will be persistent through all GWT pages -->
         </table>
    </body>
    </html>

Velocity 在服务器上运行,JavaScript 在客户端上运行,无法访问服务器的任何文件。

您可以使用 Velocity 在 JavaScript 块中设置值,并让 JS 函数使用这些值。

<script type='text/javascript'>
var startValue = '$debug.value';
</script>