日期:2014-05-18  浏览次数:20707 次

求助:当WEB的图片不存在时,怎样将IE上那个默认的叉叉图片换成自定义的?
RT

------解决方案--------------------
web上的图片是怎么显示出来的啊?
我做过一个,人物个人信息显示照片,如果照片不存在(数据库读出个人信息时判断),就根据性别读一个系统默认的图片,显示到前台 <img src= "XXX.do?method=showPhoto&personId=XXX "> 。后边DispathAction处理,
public ActionForward showPhoto(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int sex=1;
//一些和问题无关的处理,得到用户的真实性别且此用户无照片 sex=personVO.getSex();
byte[] b = null;
try {
response.setContentType( "image/* "); // 设置返回的文件类型
OutputStream toClient = response.getOutputStream(); // 得到向客户端输出二进制数据的对象
if(sex==1){
InputStream is = getServlet().getServletContext().getContext(request.getContextPath()).getResourceAsStream( "images/photo-man.gif ");//images/photo-man.gif在webContent下
b = new byte[is.available()];
is.read(b);
toClient.write(b); // 输出数据
toClient.close();
}
else{
InputStream is = getServlet().getServletContext().getContext(request.getContextPath()).getResourceAsStream( "images/photo-woman.gif ");
b = new byte[is.available()];
is.read(b);
toClient.write(b); // 输出数据
toClient.close();
}
}
} catch (IOException e) {
log.error(e.getMessage());
}

return null;
}
------解决方案--------------------
帮顶。。。
------解决方案--------------------
<img onerror=
------解决方案--------------------
<script type= "text/javascript ">
var imgErr = function(imgObj){
imgObj.parentNode.innerHTML = ' <img src= "yourimage "> ';
}
</script>
<div>
<img id= "image " src= "123.323 " onerror= "imgErr(this); " />
</div>