日期:2014-05-19  浏览次数:20783 次

Spring MVC的web.xml配置后显示不了图片
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
<!-- 定义Servlet名称 -->
<servlet-name>dispatcherServlet</servlet-name>
<!-- Servlet具体实现类 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 初始化上下文对象 -->
<init-param>
<!-- 参数名称 -->
<param-name>contextConfigLocation</param-name>
<!-- 加载配置文件 -->
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<!-- 设置启动的优先级 -->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 采用通配符映射所有以html类型的请求 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
 
 
 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


配置这样的web.xml后,图片就显示不了。。路径没问题,在MyEclipse能显示,浏览器上显示不了。。
MyJsp.jsp是这样的
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
     <table width="449" height="238" align="center" background="./img/index.jpg">
  <tr>
<td height="45" colspan="3">asdasd</td>
</tr>
  </table></html>


如果在Web.xml把 <servlet>
<!-- 定义Servlet名称 -->
<servlet-name>dispatcherServlet</servlet-name>
<!-- Servlet具体实现类 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 初始化上下文对象 -->
<init-param>
<!-- 参数名称 -->
<param-name>contextConfigLocation</param-name>
<!-- 加载配置文件 -->
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<!-- 设置启动的优先级 -->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 采用通配符映射所有以html类型的请求 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>