tomcat不能完整的加载图片

仼往_cheg 2014-10-11 06:09:29
用的是tomcat 6 +myeclipse8.5,在网上查了很久居然没有人遇到过,没有报错只是加载不完整。。。。

放在index.jsp里就显示完整!




放在login.jsp 就不行了。



这是web.xml的代码

<?xml version="1.0" encoding="UTF-8" ?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>oppensession</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
</web-app>




struts2的配置文件

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<!--<constant name="struts.enable.DyamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="false"></constant>
<constant name="struts.i18n.encoding" value="UTF-8" />
--><!--<constant name="struts.convention.result.path" value="/WEB-INF/pages"/>
<constant name="struts.convention.package.locators" value="web,action"/>
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.configuration.xml.reload" value="true"/>-->
<!--<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>-->
<package name="front" extends="struts-default">
<global-results>
<result name="fail">/index.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="fail" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
</package>

<package name="ations" extends="front" namespace="/actions">
<action name="login" class="ua" method="login">
<result name="success">/admin/login_success.jsp</result>
<result name="fail">/admin/login_fail.jsp</result>
</action>
<action name="input" class="ua" method="input">
<result name="input">/login.jsp</result>
</action>
</package>
</struts>



页面的目录结构



login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>用户登录</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
overflow:hidden;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('images/login_09_1.gif','images/login_10_1.gif')">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#02395f"> </td>
</tr>
<tr>
<td height="607" align="center" background="images/login_02.gif"><table width="974" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="331" background="images/login_01.jpg"> </td>
</tr>
<tr>
<td height="116"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="393" height="116" background="images/login_05.gif"> </td>
<td width="174">
<form action="#" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="81" background="images/login_06.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="24%"><div align="center"><font style="height:1;font-size:9pt; color:#bfdbeb;filter:glow(color=#1070a3,strength=1)">用户</font></div></td>
<td width="76%" height="25"><input type="text" name="textfield" style="width:125px; height:20px; background:#32a2e3; font-size:12px; border:solid 1px #0468a7; color:#14649f;"></td>
</tr>
<tr>
<td><div align="center"><font style="height:1;font-size:9pt; color:#bfdbeb;filter:glow(color=#1070a3,strength=1)">密码</font></div></td>
<td height="25"><input type="password" name="textfield2" style="width:125px; height:20px; background:#32a2e3; font-size:12px; border:solid 1px #0468a7; color:#14649f;"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="35"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50" height="35"><img src="images/login_08.gif" width="50" height="35"></td>
<td width="46"><a href="#"><img src="images/login_09.gif" name="Image1" width="46" height="35" border="0" id="Image1" onMouseOver="MM_swapImage('Image1','','images/login_09_1.gif',1)" onMouseOut="MM_swapImgRestore()"></a></td>
<td width="45"><a href="#"><img src="images/login_10.gif" name="Image2" width="45" height="35" border="0" id="Image2" onMouseOver="MM_swapImage('Image2','','images/login_10_1.gif',1)" onMouseOut="MM_swapImgRestore()"></a></td>
<td width="33"><img src="images/login_11.gif" width="33" height="35"></td>
</tr>
</table></td>
</tr>
</table></form></td>
<td width="407" background="images/login_07.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="160" background="images/login_12.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#02609c"> </td>
</tr>
</table>
</body>
</html>




...全文
390 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
仼往_cheg 2014-10-12
  • 打赏
  • 举报
回复
引用 9 楼 neo8856 的回复:
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 是basepath的问题,基路径导致图片无法显示 http://blog.csdn.net/randomnet/article/details/8630754
没错,加了basepath就ok了!3Q!
  • 打赏
  • 举报
回复
相对路径写的不对,自己多练一下相对路径的写法。
-阿克蒙德- 2014-10-11
  • 打赏
  • 举报
回复
右键查看源文件,找到图片路径,点进去看看
-阿克蒙德- 2014-10-11
  • 打赏
  • 举报
回复
楼上和楼上的楼上均正解
wobuzaidanchun 2014-10-11
  • 打赏
  • 举报
回复
用脚趾头想都知道是路径问题
  • 打赏
  • 举报
回复
图片路径问题
Kifile 2014-10-11
  • 打赏
  • 举报
回复
你的 img 对应的资源是 img src="images/login_08.gif" 但是实际上,你的 login.jsp 位于 companyINfo***/actions/下,此时html 查找对应图片就回去companyINfo***/actions/ images 下查找 但是你又很明显应该没有这个文件夹,所以会报错 对于这种情况,你可以在 src 里改成/images/login_08.gif, 这是为了让 html 从根节点下开始查找,使用绝对路径
neo8856 2014-10-11
  • 打赏
  • 举报
回复
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 是basepath的问题,基路径导致图片无法显示 http://blog.csdn.net/randomnet/article/details/8630754
S117 2014-10-11
  • 打赏
  • 举报
回复
用调试工具,firebug什么的,看看图片的路径,这应该是路径问题,和什么服务器没关系
bayougeng 2014-10-11
  • 打赏
  • 举报
回复
看源码,如果源码没错,就是资源定位出问题了。 如果都没问题,那就是浏览器的问题

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧