Java 将图像添加到 eclipse web 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19385955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:41:13  来源:igfitidea点击:

adding image to eclipse web project

javaimagewebproject

提问by carlos palma

Well, this is embarrasing...I can't seem to be able to add a humble image to a java web project in eclipse. What I did was that I created a folder called images inside WebContent, and then tried adding it in two ways, directly pasting it and using add/file, and advanced, which basically asks for a route to the image insider the hard drive.

嗯,这很尴尬……我似乎无法在 eclipse 中向 java web 项目添加一个不起眼的图像。我所做的是在 WebContent 中创建了一个名为 images 的文件夹,然后尝试通过两种方式添加它,直接粘贴它并使用 add/file 和高级,这基本上要求提供到硬盘驱动器内部图像的路径。

The HTML syntax is here:

HTML 语法在这里:

<img border="0" src="WebContent/images/network.jpg"
     alt="Pulpit rock" width="304" height="228">

I tried it with and without WebContent. I am sure there's something I'm missing, but after a couple hours decided to get help.

我在有和没有 WebContent 的情况下都尝试过。我确定我遗漏了一些东西,但几个小时后决定寻求帮助。

Thanks in advance for any assistance.

提前感谢您的任何帮助。

采纳答案by Elemental

You should in general try to avoid absolute paths. Specifically I believe from a normal web project you should try something like:

通常,您应该尽量避免使用绝对路径。具体来说,我相信从一个普通的网络项目中你应该尝试这样的事情:

<img border="0" src="images/network.jpg"
     alt="Pulpit rock" width="304" height="228">

Which works like a charm for me.

这对我来说就像一个魅力。

回答by user1687079

You have to add the image within the eclipse project structure for eclipse to package it and have it available on the webserver. Just having the image on your local file system doesn't work. To do this, drag and drop the file from your file system onto the eclipse project tree folder.

您必须在 eclipse 项目结构中为 eclipse 添加图像以将其打包并在 web 服务器上可用。仅将图像放在本地文件系统上是行不通的。为此,请将文件从文件系统拖放到 eclipse 项目树文件夹中。