Html 图片没有显示在浏览器中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6402600/
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-29 09:11:17  来源:igfitidea点击:

Image is not showing in browser?

htmlimagejsp

提问by avirk

<body style="background-color: paleturquoise">
    <h2 style="color: red">Duke's soccer League: Home Page<br/></h2>
    <ul style="list-style-type: circle">
        <li style="font-size: larger"><a href="league_list.in">All Leagues list</a></li>
        <li style="font-size: larger">Register for a League (TBA)<br/><br/></li>
    </ul>
    <h2 style="color: red">League Administrator</h2>
    <ul style="list-style-type: square">
        <li style="font-size: larger"><a href="add_league.in">Add a new League (TBA)</a></li>

        <img  src="C:\Users\VIRK\Desktop.jpg" width="400" height="400" ></img>

</ul>
</body>  

I am currently practice with JSP and I try this html code to make a web page on NetBeans IDE 7.0 but when I'm build and run the page no error in code but the image is not showing in the browser.

我目前正在练习 JSP,我尝试使用此 html 代码在 NetBeans IDE 7.0 上制作网页,但是当我构建并运行该页面时,代码中没有错误,但图像未显示在浏览器中。

Edited:

编辑:

enter image description here

在此处输入图片说明

Here I have given the screenshot of the NetBeans IDE where you can see the image is existing in Web-INF folder and the index.jsp page too and I tried with "/"before the image name but it won't work. The exact path of my project is C:\Users\VIRK\Documents\NetBeansProjects\practiceJSP .

这里我给出了 NetBeans IDE 的屏幕截图,您可以在其中看到图像存在于 Web-INF 文件夹和 index.jsp 页面中,我"/"在图像名称之前尝试过,但它不起作用。我的项目的确切路径是 C:\Users\VIRK\Documents\NetBeansProjects\practiceJSP 。

<img  src="/66.jpg" width="400" height="400" ></img>

回答by avirk

I find out the way how to set the image path just remove the "/"before the destination folder as "images/66.jpg"not "/images/66.jpg"And its working fine for me.

我找到了如何设置图像路径的方法,只需将"/"目标文件夹之前的文件夹删除为"images/66.jpg"not"/images/66.jpg"并且它对我来说工作正常。

回答by r.piesnikowski

You put inside img tag physicalpath you your image. Instead of that you should put virtualpath (according to root of web application) to your image. This value depends on location of your image and your html page.

你把你的图像放在 img 标签物理路径中。取而代之的是,您应该将虚拟路径(根据 Web 应用程序的根目录)放置到您的图像中。此值取决于图像和 html 页面的位置。

for example if you have:

例如,如果您有:

/yourDir
-page.html
-66.jpg

in your page.html it should be something like that:

在您的 page.html 中,它应该是这样的:

<img  src="66.jpg" width="400" height="400" ></img>

second scenario:

第二种情况:

/images
-66.jpg
/html
page.html

So your img should look like:

所以你的 img 应该是这样的:

<img  src="../images/66.jpg" width="400" height="400" ></img>

回答by Saurabh

Your path should be like this : "http://websitedomain//folderpath/66.jpg">

你的路径应该是这样的:“http://websitedomain//folderpath/66.jpg">

<img  src="http://websitedomain/folderpath/66.jpg" width="400" height="400" ></img>

回答by Kon

I don't know where you're running the site from on your computer, but you have an absolute file path to your C drive: C:\Users\VIRK\Desktop\66.jpg

我不知道您在计算机上从哪里运行该站点,但是您有 C 盘的绝对文件路径:C:\Users\VIRK\Desktop\66.jpg

Try this instead:

试试这个:

<img  src="[PATH_RELATIVE_TO_ROOT]/66.jpg" width="400" height="400" />

UPDATE:

更新:

I don't know what your $PROJECTHOMEis set to. But say for example your site files are located at C:\Users\VIRK\MyWebsite. And let's say your images are in an 'images' folder within your main site, like so: C:\Users\VIRK\MyWebsite\images.

我不知道你$PROJECTHOME的设置是什么。但是,例如您的站点文件位于 C:\Users\VIRK\MyWebsite。假设您的图像位于主站点内的“图像”文件夹中,如下所示:C:\Users\VIRK\MyWebsite\images。

Then in your HTML you can simply reference the image within the images folder relative to the site, like so:

然后在您的 HTML 中,您可以简单地引用相对于站点的图像文件夹中的图像,如下所示:

<img  src="images/66.jpg" width="400" height="400" />

Or, assuming you're hosting at the root of localhost and not within another virtual directory, you can do this (note the slash in the beginning):

或者,假设您托管在 localhost 的根目录而不是另一个虚拟目录中,您可以这样做(注意开头的斜杠):

<img  src="/images/66.jpg" width="400" height="400" />

回答by Rajesh Acharya

all you need to do is right click on the jsp page in the browser, which might look like "localhost:8080/images.jpg, copy this and paste it where the image is getting generated

您需要做的就是在浏览器中右键单击 jsp 页面,它可能看起来像“localhost:8080/images.jpg,复制它并将其粘贴到生成图像的位置

回答by Gourav

I had same kind of problem in Netbeans.

我在 Netbeans 中遇到了同样的问题。

I updated the image location in the project and when I executed the jsp file, the image was not loaded in the page.

我在项目中更新了图片位置,当我执行jsp文件时,图片没有加载到页面中。

Then I clean and Built the project in Netbeans. Then it worked fine.

然后我在 Netbeans 中清理并构建了该项目。然后它工作得很好。

Though you need to check the image actually exists or not using the image URL in the browser.

尽管您需要使用浏览器中的图像 URL 来检查图像是否实际存在。

回答by Jeff

I had a problem where the images would not show and it wasn't the relative path. I even hard coded the actual path and the image still did not show. I had changed my webserver to run on port 8080 and neither

我有一个问题,图像不会显示,而且它不是相对路径。我什至硬编码了实际路径,图像仍然没有显示。我已将我的网络服务器更改为在端口 8080 上运行,但两者都没有

<img src="c:/public/images/<?php echo $image->filename; ?>" width="100" />
<img src="c:/public/images/mypic.jpg" width="100" />

would not work.

不会工作。

<img src="../../images/<?php echo $photo->filename; ?>" width="100" />

Did not work either. This did work :

也没有用。这确实有效:

<img src="http://localhost:8080/public/images/<?php echo $image->filename; ?>" width="100" />

回答by Sahil Shinde

do not place *jsp or *html in root folder of webapp and images you want to display in same root folder browser cannot acess the image in WEB-INF folder

不要将 *jsp 或 *html 放在 webapp 的根文件夹中,并且要在同一个根文件夹中显示的图像浏览器无法访问 WEB-INF 文件夹中的图像

回答by Nupur

I also had a similar problem and tried all of the above but nothing worked. And then I noticed that the image was loading fine for one file and not for another. The reason was: My image was named image.jpg and a page named about.html could not load it while login.html could. This was because image.jpg was below about and above login. So I guess login.html could refer to the image and about.html couldn't find it. I renamed about.html to zabout.html and re-renamed it back. Worked. Same may be the case for images enclosed in folders.

我也遇到了类似的问题并尝试了上述所有方法但没有任何效果。然后我注意到图像对一个文件加载正常,而不是另一个文件。原因是:我的图像名为 image.jpg 并且名为 about.html 的页面无法加载它,而 login.html 可以。这是因为 image.jpg 低于登录名。所以我猜 login.html 可以引用图像而 about.html 找不到它。我将 about.html 重命名为 zabout.html 并将其重新命名。工作了。包含在文件夹中的图像可能也是如此。

回答by ?mer

the easy way to do it to place the image in Web Content and then right click on it and then open it by your eclipse or net beans web Browser it will show the page where you can see the URL which is the exact path then copy the URL and place it on src=" paste URL " ;

最简单的方法是将图像放置在 Web 内容中,然后右键单击它,然后通过 eclipse 或 net beans web 浏览器打开它,它将显示您可以看到 URL 的页面,该 URL 是确切路径,然后复制URL 并将其放在 src=" paste URL " 上;