Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 图像未显示(一个图像显示,另一个图像未显示)_Java_Image_Jsp_Servlets_Jsp Tags - Fatal编程技术网

Java 图像未显示(一个图像显示,另一个图像未显示)

Java 图像未显示(一个图像显示,另一个图像未显示),java,image,jsp,servlets,jsp-tags,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

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

NewFile.jsp

。我的问题是Gmail图像正在显示,但Yahoomail图像未显示。结果-->。为什么这样,有什么问题。请向我提出您的宝贵意见。

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


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

您应该检查图像的名称。我提供的currect name有任何疑问请查看我提供的链接,您自己尝试过什么吗?就像上面雅虎的write href标签和gmail的一样。它工作正常吗?如果我用gmail图像重命名这两个图像,它会显示完美的gmail符号,但当放置yahooimage时,图像不会显示。为什么?这里只有yahooimage的问题。那个问题是什么?你是通过web浏览器访问图像的,就像file:///home/mpatil/Desktop/Ram/rocking/Examples/WebContent/images/I 我不明白。request.getContextPath()不返回本地文件系统路径,那么您就不能拥有一个以“file://”开头的路径,因为
/images/yahooimage.jpg“width=”1..
浏览器页面中src属性的值是多少?@servletsram:也要避免使用scriptlet,它们纯粹是邪恶的。请改用EL+JSTL或OGNL+S2。