java - 图像未显示(一张图像正在显示,另一张图像未显示)

标签 java image jsp servlets jsp-tags

Servlet 程序

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Redirect
 */
@WebServlet("/Redirect")
public class Redirect extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
    System.out.println("servlet is intialized");
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("image/jpeg");  
        request.getRequestDispatcher("/myhtml.jsp").forward(request, response);     

    }



}

JSP文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
    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="image/jpeg; charset=UTF-8">
<title>NewFile.jsp</title>
</head>
<body>
<a href="http://www.gmail.com"><img src="<%=request.getContextPath()%>/images/gmailimage.jpg" width="100" height="100"></a>
<a href="http://www.yahoomail.com"><img src="<%=request.getContextPath()%>/images/yahooimage.jpg" width="100" height="100"></a>
</body>
</htm

图像文件夹是--> /image/558ON.png 。我的问题是 Gmail 图像显示,但 Yahoomail 图像未显示。结果 --> /image/dH5AT.png .为什么会这样,哪里出了问题。请提出你的宝贵意见。

最佳答案

您已经尝试过检查图像 URL 了吗? 使用 Chrome 的开发者工具 (F12),您可以选择一个元素并检查其内部属性。查看其 URL 并尝试将其复制并粘贴到地址栏中。

可能你看不到它,然后你可以尝试手动调整 URL。

关于java - 图像未显示(一张图像正在显示,另一张图像未显示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20069222/

相关文章:

javascript - 在新图像完全加载时添加微调器

Django 管理员通过 ImageField 链接到图像

java - 将表 html 行值读取到 servlet 到另一个 jsp 页面以进行编辑

javascript - 如何在JSP字符串变量中插入JavaScript变量

java - Android Studio - Gradle 同步错误

Java拼图: modifiers

java - 使用适用于 OpenShift 的 Jboss Tools 插件进行部署会生成错误 invalid target release : 1. 8

iphone - iOS - 异步缓存和加载图像

java - 在浏览器禁用 cookie 时管理 session

java - 在终端中同时执行多个while true java程序