当前位置: 代码迷 >> Java Web开发 >> 关于图片预览有关问题
  详细解决方案

关于图片预览有关问题

热度:8975   发布时间:2016-04-10 22:30:13.0
关于图片预览问题
我在html中能够成功预览本地图片,但是换成jsp后,相同的代码,路径却变了,前缀是变成了“c:\fakepath\” + 图片名字,这是为什么啊?html的时候还好好的啊。。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS上传前预览图片</title>
<script type="text/javascript" language="javascript">

function PreviewImg(imgFile){  
    var newPreview = document.getElementById("newPreview");    
    var imgDiv = document.createElement("div");
    document.body.appendChild(imgDiv);
    imgDiv.style.width = "118px";    imgDiv.style.height = "127px";
    imgDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";   
alert(imgFile.value);
    imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
    newPreview.appendChild(imgDiv);    
    var showPicUrl = document.getElementById("showPicUrl");
    showPicUrl.innerText=imgFile.value;
    newPreview.style.width = "80px";
    newPreview.style.height = "60px";
}

</script>
    </head>
    <body>     
        <p>兼容IE6、IE7</p>
        <div id="newPreview"></div>
        <div id="showPicUrl"></div>
        <hr />
        <p>
            选择图片:<input type="file" size="20" onchange="javascript:PreviewImg(this);" />
        </p>
    </body>
</html>

这是我找的代码,可以用ie9以下的实现上传,求大神知道为什么jsp就不成了啊?“C:\fakepath\DSC_07g.jpg”这是是jsp的路径
------解决方案--------------------
jsp 不是 html 哦
最好用相对路径。
------解决方案--------------------
引用:
jsp 不是 html 哦
最好用相对路径。
对啊,你把图片拷进项目里,然后再写项目里的路径!
------解决方案--------------------
引用:
上传图片之前啊,怎么放到项目里

你可以上传到项目的某个目录下啊
例如:C:\Documents and Settings\Administrator\Workspaces_MyTime\BBS_Servlet\WebContent\IMG\test.jpg
------解决方案--------------------
引用:
上传图片之前啊,怎么放到项目里

和webroot平级新建一个文件夹,比如img。图片路径是./img/图片.jpg
  相关解决方案