检票口目录结构

发布于 2024-08-04 07:44:41 字数 98 浏览 1 评论 0原文

我正在尝试找出 wicket 的目录结构。我根本不明白! 假设我想加载带有 images/logo.gif 或类似内容的图像。我必须将图像文件夹放在哪里? 请帮我解决这个问题! ;)

I'm trying to figure out the directory structure of wicket. I don't get it at all!
Let's say I wanna load an image with images/logo.gif or something like that. Where do I have to place the images folder?
Please help me with this! ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我三岁 2024-08-11 07:44:41

Wicket 提倡通过 OOP 范式思考整个网页,其中包括资源处理。

因此,如果您的 SomePage extends WebPage 位于包 myprogram.view.pages 中,您很可能应该将图像等添加到 myprogram.view.pages.assets< /code> (或其他类似名称的逻辑包),然后通过调用将图像添加到 SomePage 源中。

add(new Image("id", new ResourceReference(this.getClass(), "assets/logo.gif")));

这样,您的所有页面、其组件以及当然相关的资产都将具有合理的结构( 我是唯一一个对人们仍然将所有 CSS 样式塞到一个巨大的样式表中感到恼火的人吗?)它与其他一切都分离。

现在是高级部分:对于页面上的静态元素,您很可能不想执行上述操作,因为这显然是一种重量级的方法,并且您实际上可能希望允许设计师决定使用哪个徽标图像。对于此类事情,请

<wicket:link>
    <img src="images/logo.gif" />
</wicket:link>

直接在标记文件中使用。 wicket:link 标签将自动链接图像资源指向正确的文件(路径与 SomePage.class 相关!),甚至自动处理缓存。

Wicket promotes thinking entire web pages through OOP paradigms and that includes recource handling.

So, if your SomePage extends WebPage is in package myprogram.view.pages, you should most likely add images etc. to myprogram.view.pages.assets (or other similarly named, logical package) and then add the image in the SomePage source by calling

add(new Image("id", new ResourceReference(this.getClass(), "assets/logo.gif")));

This way you will have all your pages, its components and of course related assets in reasonable structure (am I the only one annoyed that people still cram all their CSS stylings to one huge stylesheet?) which is detached from everything else.

And now the advanced parts: For static elements on your page you most likely don't want to do the above since it's obviously somewhat heavyweight way to do it and you may actually want to allow the designer guy to decide which logo image to use. For these sort of things, use

<wicket:link>
    <img src="images/logo.gif" />
</wicket:link>

straight in the markup file. The wicket:link tag will automatically link the image resource pointing to the correct file (path is relevant to the SomePage.class!) and even automagically handles caching.

一江春梦 2024-08-11 07:44:41

您可以直接在项目的根目录中创建图像文件夹。即你的战争档案必须包含 META-INF、WEB-INF、根级别的图像。或者在 servlet 容器中的 Web 应用程序文件夹的根目录中。然后在 html 中引用它,例如

<img src="images/pic1.jpg"/>

如果您从 java 代码引用图像,则必须使其相对于 servlet 路径。可以通过 servlet 上下文访问它

class MyPage extends WebPage {
  public MyPage() { 
     final ServletContext ctx = ((WebApplication) getApplication()).getServletContext();
     File imgFile = new File(ctx.getRealPath("/images/pic1.jpg"));
   }
}

You can create image folder directly in root of your project. i.e. your war archive must contain META-INF, WEB-INF, images at root level. Or in root of your web app folder in servlet container. Then reference it in your html's like

<img src="images/pic1.jpg"/>

If you're referencing the image from the java code, you must make it relative to your servlet path. It can be acessed through servlet context by

class MyPage extends WebPage {
  public MyPage() { 
     final ServletContext ctx = ((WebApplication) getApplication()).getServletContext();
     File imgFile = new File(ctx.getRealPath("/images/pic1.jpg"));
   }
}
末蓝 2024-08-11 07:44:41

在 Netbeans 中,它位于源包 tld.domain.project 下
在那里你创建一个名为 images 的新文件夹,它就可以工作了

In Netbeans it's under Source Packages tld.domain.project
There you make a new folder called images and it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文