在码头项目中将html/css/javascript之类的静态文件存储在哪里? [英] Where to store static files like html/css/javascript in a jetty project?

查看:89
本文介绍了在码头项目中将html/css/javascript之类的静态文件存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用码头运行的Maven项目:

I have a maven project that I run using jetty:

$ mvn run:jetty

我应该在项目的哪里存储HTML,CSS,Javascript,图像等静态文件?

Where in my project should I be storing my static files like HTML, CSS, Javascript, images?

我的布局使用的是简单的Web应用拱形类型:

My layout is using a simple web app arch type:

/src/main/java/webapp/web-inf/views/

我应该在那里创建一个名为例如的文件夹资产"?

Should I just create a folder there named e.g. 'assets' ?

然后我的视图页面将以某种方式引用/assets文件夹?我对于在html页面中使用什么路径来引用类似这样的图像感到困惑:

And then my view pages will reference the /assets folder somehow? I'm confused as to what path I will use in my html pages to reference an image like:

/assets/images/logo.png

推荐答案

这不是Jetty问题,而是一般的Java webapp问题.如果您打算直接提供它们(例如* .css,*.css,图像等),请将它们放在WEB-INF上方但在docroot下方的某个位置. Java WebApp都是以下基本目录结构.

This isn't so much a Jetty question as it is a general Java webapp question. If you plan to serve them out directly (like *.css, *.css, images, etc), put them somewhere above WEB-INF but below your docroot. Java WebApps are all the following basic directory structure.

<docroot>
  +WEB-INF/
    +lib/
    +classes/

<docroot>中的任何内容都可以直接通过http直接访问. WEB-INF及以下的任何内容都不是.一个只有一页(index.jsp),一个图像目录中的图像及其配置文件(web.xml)的真正简单的Web应用程序看起来像这样.

Anything in <docroot> is reachable directly through straight up http. Anything WEB-INF and below is not. A really simple webapp with one page (index.jsp), one image in an images directory, and its configuration file (web.xml) would look like this.

index.jsp
images/bob.jpg
WEB-INF/
  web.xml
  lib/
  classes/

在index.jsp中,您可以像这样引用bob.jpg ...

In index.jsp you could reference bob.jpg like...

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

这篇关于在码头项目中将html/css/javascript之类的静态文件存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆