img标签图像不加载在铬 [英] img tag image not loading in chrome

查看:96
本文介绍了img标签图像不加载在铬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究动态Web应用程序,并且需要从本地文件在jsp上显示图像。当我在eclipse中运行它时,该程序运行得非常好,但是当我在chrome中尝试相同时,它不会加载图像。

 <%@ page language =javacontentType =text / html; charset = ISO-8859-1
pageEncoding =ISO-8859-1%>
<!DOCTYPE html>
< html>
< head>
< meta charset =ISO-8859-1>
< title>图片处理器< / title>
< / head>
< body bgcolor =BLACK>
< h3 style =color:WHITEalign =Center>处理您的图片< / h3>
< img src =E:\Pics\Wallpapers\me.jpgwidth = 300 height = 400>
<%
String name = request.getParameter(path);
session.setAttribute(path,name);
%>
< / body>
< / html>


解决方案

您需要了解网络的工作原理。

例如,法国的用户使用浏览器访问 http://foo.bar.com上的网页。这发送一个HTTP请求到例如位于巴西的服务器foo.bar.com。服务器返回一个HTML页面,其中包含例如

 < img src =image.jpg/> 

当它看到这个时,浏览器会向巴西的服务器发送另一个HTTP请求,要求图片在 http://foo.bar.com/image.jpg



请注意,用户看到的所有内容浏览器来自位于其他地方的W​​eb服务器。巴西的网站无权在法国的用户计算机上打开文件。这将构成一个重大的安全问题,因为该网站可以收集有关最终用户机器上的文件的私人信息。



您可能对以下事实感到困惑:在开发过程中,服务器和客户端机器是同一个。但是这并没有改变任何东西。在您的应用程序的网页上显示的所有内容必须来自Web服务器,通过HTTP。您不能简单地将图像的来源设置为文件路径。图像的路径必须指向Web应用程序提供的图像,部署在Web服务器中。


I have been working on a dynamic web application and that requires to display a image on the jsp from my local files. Ant the program is running absolutely fine when I run it in eclipse but when I try the same in chrome it does not load the images.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Image Processor</title>
</head>
<body bgcolor="BLACK">
<h3 style="color : WHITE" align="Center">Process Your Image</h3>
<img src ="E:\Pics\Wallpapers\me.jpg" width=300 height=400>
<%
String name = request.getParameter( "path" );
session.setAttribute( "path", name );
%>
</body>
</html>

解决方案

You need to understand how the web works.

You have a user, located for example in France, using his browser to visit a web page at http://foo.bar.com. This sends an HTTP request to the server foo.bar.com located, for example, in Brazil. The server sends back an HTML page containing, for example

<img src="image.jpg" />

When it sees this, the browser sends another HTTP request to the server in Brazil, asking for the image at http://foo.bar.com/image.jpg.

Note that everything the user sees in the browser comes from a web server, located elsewhere. A web site in Brazil is not authorized to open files on the user's machine in France. That would constitute a major security issue, since the web site could gather private information about the files on the end user's machine.

You're probably confused by the fact that, during development, the server and the client machine are the same one. But that doesn't change anything. Everything displayed on the web page of your app must come from the web server, over HTTP. You can't simply set the source of an image to a file path. The path of the image must point to an image served by your webapp, deployed in your web server.

这篇关于img标签图像不加载在铬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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