【问题标题】:Rhino variables in JSPJSP 中的 Rhino 变量
【发布时间】:2023-03-22 03:40:01
【问题描述】:

我的jsp中有这个:

<%
    Scriptable scope = Context.enter().initStandardObjects();
    scope.put( "foo", scope,  Context.toObject( "foo", scope ) );
%>

<script type="text/javascript">
   function doSomething() {
      // this works fine, so I can tell Rhino is working to some extent
      var now = new Packages.java.util.Date();
      alert(now);

      // but this comes back as an undefined variable - why?
      alert(foo);
   }
</script>

我完全感到困惑 - 我认为通过将字符串值(“foo”)放在默认范围内,我可以在 javascript 上下文中看到它,但是,我不能。如果不是因为 'now' 变量可以正常工作,这对我来说是有意义的。

有谁知道我在这里做错了什么?

【问题讨论】:

    标签: java javascript jsp rhino


    【解决方案1】:

    不,不能直接访问它。您必须使用 JSP 标记来获得它。 之类的东西。

    有教程here

    现在我重新阅读并看到您在函数中执行此操作。使用上述内容应该仍然有效。但是,将值传递给函数并将 JSP 排除在函数声明之外可能是更好的做法。

    【讨论】:

      猜你喜欢
      • 2013-10-28
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2010-12-02
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      相关资源
      最近更新 更多