无法在JSP中显示图像 [英] Can't display images in JSP

查看:83
本文介绍了无法在JSP中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在JSP中显示图像(并且无法通过SRC访问外部Javascript / jQuery等其他内容)。以下JSP页面只包含一个< img> 标记,无法显示SRC所在的图像。

I can't display images in JSP (and can't access other things like external Javascript/jQuery through SRC). The following JSP page just contains one <img> tag that can not display the image located by the SRC.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="Temp.htm" method="post">
            <img src="/images/temp.jpg" alt="Not available">
        </form>
    </body>
</html>

图片位于 / WEB-INF / jsp / images 。我还试图改变图像位置,并确保给予SRC的路径的所有时间都是正确的,但事实并非如此。 没有框架的应用程序也是如此。它完美地运作。我在这里缺少什么?

The images are in /WEB-INF/jsp/images. I have also tried to change the image location and ensure all the times that the path given to SRC is correct still it didn't. The same is possible with the applications without the framework. It works there perfectly. What am I missing here?

推荐答案

首先, / WEB -INF 无法从外部访问。

First, /WEB-INF is not accessible from the outside.

其次,如果您使用 /images/temp.jpg ,浏览器将从根目录加载图像Web服务器,而不是来自Web应用程序的根目录(在上下文路径下部署)。

Second, if you use /images/temp.jpg, the browser will load images from the root of the web server, and not from the root of your web-app (which is deployed under a context path).

使用JSTL < c :url> 标记,用于从网络应用的根目录生成绝对路径:

Use the JSTL <c:url> tag to generate absolute paths from the root of the web-app:

<img src="<c:url value='/images/temp.jpg'/>" alt=.../>

这篇关于无法在JSP中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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