Jsp文件上传组件代码(一)

 一、upload.jsp(文件上传显示页面)

<%@ page contentType="text/html;charset=gb2312" %>
<%String type=request.getParameter("type");%>
<style type="text/css">
<!--
.td1 {
 font-size: 13px;
 border-bottom:1px #000000 solid;
 height:25px;
 padding-top:1px;
 padding-left:8px;
}
.td{
 font-size: 13px;
 border-bottom:1px #000000 solid;
 height:25px;
 padding-top:1px;
 padding-left:8px;
 border-left:1px #000000 solid;
}
INPUT {
 BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 12px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px
}
.input{
    border:solid 1px #000000;
 max-width:300px;
 width:250px;
 }
-->
</style>
<script>
var sz;
var img=null;
var IsCheck;
function check()
{
IsCheck=1;
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onerror",oErr);
document.body.insertAdjacentElement("beforeend",img);
if(IsCheck==0){window.location.href='upload.jsp?type=<%=type%>';return false;}
img.src=Myform.Submit.value;
if(IsCheck==1){return true;}
}
function oErr()
{
IsCheck=0;

alert("不能加载图片!请确认文件正确 JPG GIF");
window.location.href='upload.jsp?type=<%=type%>';
}
function on(){
if(document.all.Submit.value==""){
document.all.Submit.focus();
window.location.href='upload.jsp?type=<%=type%>';
return false;
}
if(sz==-1){getpize();}
if(sz>212992){
alert("图片大小不大于200KB");
window.location.href='upload.jsp?type=<%=type%>';
return false;
}else{
if(check()){
if(IsCheck==0){window.location.href='upload.jsp?type=<%=type%>';}
document.all.Myform.submit();
}
}
}
function getpize(){
 var     document.Myform.Submit.value; 
 if(s=="") window.location.href='upload.jsp?type=<%=type%>';return   false;   
 var   img    new   Image();   
 img.src    s; 
 alert("dd"); 
sz=img.fileSize;
}</script>
<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
-->
</style>
<form action="Unload.jsp?tye=<%=type%>" method="post" enctype="multipart/form-data" name="Myform">
<input name="Submit" type="file" value="提交" onChange="getpize()" class="input"> 
<input name="Submit2" type="button" class="btn_grey"  value="上传" onClick="on()">
</form>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值