简体   繁体   English

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

[英]How to read value from property file using Java Script?

I added textfield and a button in velocity script that is used through a web app. 我在通过Web应用程序使用的速度脚本中添加了文本字段和按钮。 When web app is launched start.properties file is read. 启动Web应用程序时,将读取start.properties文件。 There's a property: debug_on that can take two values 0 or 1. 有一个属性:debug_on,它可以采用两个值0或1。

So I want to display textfield and the button according to debug_on value. 所以我想根据debug_on值显示文本字段和按钮。 It can be done in velocity script via javascript, if I'm not mistaken (I'm not a pro in JavaScript), but I need to get the property value in order to move further. 如果我没有记错的话(我不是JavaScript的专业人士),可以通过javascript在Velocity脚本中完成此操作,但是我需要获取属性值才能继续操作。

How can I achieve it? 我该如何实现?

UPDATED 更新

Velocity script example where main GWT (Java) code is embedded at the end: 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 runs on the server, JavaScript runs on the client and will not have access to any of the server's files. Velocity在服务器上运行,JavaScript在客户端上运行,并且将无法访问服务器的任何文件。

You can use Velocity to set values within a JavaScript block and have a JS function use those values. 可以使用Velocity在JavaScript块内设置值,并让JS函数使用这些值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM