关于在网站404ErrorPage页面中图片相对路径的问题

  实训的时候做了一个404 ErrorPage页面,开始总是有问题,原因在于变换目录后图片就找不到了。

  比如在网站根目录下找不到相应页面就会正常显示,但是进入Admin文件夹后页面就不正常了。

  这是我们组的实训网站目录:

  关于在网站404ErrorPage页面中图片相对路径的问题

  这个是404页面,是一张图片加上热区的设置。

  

关于在网站404ErrorPage页面中图片相对路径的问题

noFile.jsp的实现如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404页面不存在</title>
</head>

<body>
<%
String path=request.getContextPath();
out.print("<img src='"+path+"/Images/error.png' alt='图片未找到' width='1265' height='649' border='0' usemap='#MapArea' />");
%>
<map name="MapArea" id="MapArea">
<area shape="poly" coords="104,23,47,79,3,120,1,80,81,2,120,3,103,22,80,46,81,46" href="index.jsp" />
</map>

</body>
</html>

这样图片就能正常显示在每一个目录了。

对了,还得在Tomcat的conf的web.xml文件中添加

 

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error/noFile.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error/error.jsp</location>
</error-page>

 

转载于:https://www.cnblogs.com/arronliao/archive/2012/06/14/2549455.html