I have a maven project that I run using jetty:
$ mvn run:jetty
Where in my project should I be storing my static files like HTML, CSS, Javascript, images?
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' ?
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
One approach is to place HTML files inside a folder, CSS files inside a folder and javascript file inside a js folder and include the javascript files from the js folder into the main HTML page.
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.
Static files are typically files such as scripts, CSS files, images, etc... that aren't server-generated, but must be sent to the browser when requested. If node. js is your web server, it does not serve any static files by default, you must configure it to serve the static content you want it to serve.
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/
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/
In index.jsp you could reference bob.jpg like...
<img src="images/bob.jpg"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With