图像未显示(正在显示一个图像而另一个图像未显示)

时间:2013-11-19 10:39:22

标签: java image jsp servlets jsp-tags

Servlets程序

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

图片文件夹是 - &gt; http://i.stack.imgur.com/558ON.png。我的问题是Gmail图片正在显示,但Yahoomail图片没有显示。结果 - &gt; http://i.stack.imgur.com/dH5AT.png。为什么这样,是错的。用你宝贵的想法告诉我。

1 个答案:

答案 0 :(得分:0)

您是否已尝试检查图片网址? 使用Chrome的开发人员工具(F12),您可以选择一个元素并检查其属性。查看其URL并尝试将其复制并粘贴到地址栏中。

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