简体   繁体   English

如何在apache wicket中加载javascript文件?

[英]How to load javascript file in apache wicket?

I have a javascript file in my web application that uses the eval(jsonString) Method. 我的Web应用程序中有一个javascript文件,它使用eval(jsonString)方法。 Eval() because I am working with JSON too. Eval()因为我也在使用JSON。

My javascript file is inside a package in netbeans. 我的javascript文件位于netbeans的包中。 What should I do to make my javascript file globally aviable for the application and browser? 我该怎么做才能使我的javascript文件对应用程序和浏览器全局可用?

The problem: The eval method won't start because the .js file is not recongnized by the browser. 问题: eval方法无法启动,因为浏览器不会识别.js文件。 JSON.parse(..) does not work too. JSON.parse(..)也不起作用。

So: How do I correctly add this javascript file to my web application. 那么:我如何正确地将此javascript文件添加到我的Web应用程序中。 So I can manipulate it by the web application during runtime and execute the eval Method? 所以我可以在运行时通过Web应用程序操作它并执行eval方法?

Any help would be great, thanks 任何帮助都会很棒,谢谢

Is that what you are searching? 那是你在找什么?

private static final ResourceReference JS = new JavaScriptResourceReference(YourPage.class, "path/to/js");

@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    response.render(JavaScriptReferenceHeaderItem.forReference(JS));
}

Put that into your page class. 把它放到你的页面类中。

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

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