⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload.jsp

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JSP
字号:
<%@page language="java" contentType="text/html;charset=GBK"%>
<%@page import="java.util.*,java.text.*,java.io.*,com.util.DealString"%>
<%
	DealString ds = new DealString();
	//上传文件信息
	String strfile = ds.toGBK((String)request.getParameter("strfile"));
	String strname = ds.toGBK((String)request.getParameter("strname"));
	String strsize = ds.toString((String)request.getParameter("strsize"));
	String cursize = ds.toString((String)request.getParameter("cursize"));
	String onesize = ds.toString((String)request.getParameter("onesize"));

	String sumsize = ds.toString((String)request.getParameter("sumsize"));
	String upmonth = ds.toString((String)request.getParameter("upmonth"));
	String count = ds.toString((String)request.getParameter("count"));
	String savedir = ds.toString((String)request.getParameter("savedir"));				//上传路径

	String err = ds.toString((String)request.getParameter("err"));

	boolean have = true ;
	//把原文件名串分割成数组
	String[] t_strfile=strfile.split(",");
	String[] t_strname=strname.split(",");
	String[] t_strsize=strsize.split(",");
	if(!strfile.equals("")&&t_strfile.length==(Integer.parseInt(count)+1)||count.equals("1")&&t_strfile.length==1&&!strfile.equals(""))
		have = false ;

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>文件上传</title>
<link rel=stylesheet href="../index.css" type="text/css">
<style type="text/css">
<!--
.style5 {font-size: 14px}
-->
<!--
.style6 {font-size: 12px}
-->
</style>
</head>
<BODY topmargin=15 leftmargin=15 onunload="fujianunload()" bgcolor="#EFEFEF">
<CENTER>
<FIELDSET align=left>
  <LEGEND align=left><span class="style6"><font color="#669966">上传面板</font></span></LEGEND>
<br>
<TABLE width=70% border=0 cellspacing=1 cellpadding=3 style="border-collapse: collapse" bgcolor="#FF9900" >
	<TBODY>
	  <tr>
		  <td width="50%" align=center bgColor="#EFEFEF">
			  <span class="style5"><B><font color="#669966">文 件 名 称</font></B></span>
		  </td>
		  <td width="30%" align=center bgColor="#EFEFEF">
		      <span class="style5"><B><font color="#669966">共<%=ds.toMKByte(Long.parseLong(cursize))%></font></span>
		  </td>
		  <td width="20%" align=center bgColor="#EFEFEF">
			  <span class="style5"><B><font color="#669966">操 作</font></B></span>
		  </td> 
	  </tr>
<%
	

	int c=0;
	for (int i=0;i<t_strfile.length;i++){
		if(!t_strfile[i].equals("")){
			c++;
	%>
	  <tr>
		   <td align=left bgColor="#EFEFEF">
				<span class="style5"><font color="#669966"><%=t_strfile[i]%></span>
		   </td>
		   <td align=center bgColor="#EFEFEF">
				<span class="style5"><font color="#669966"><%=ds.toMKByte(Long.parseLong(t_strsize[i]))%></span>
		   </td>
		   <td align=center bgColor="#EFEFEF">
				<span class="style5"><font color="#669966"><a href="#" onclick="del('<%=t_strname[i]%>','<%=t_strsize[i]%>');return false;">删除</a></span>
		   </td>
	  </tr>
	<%
		}
	}for (int i=c;i<Integer.parseInt(count);i++){
	%>
	  <tr>
		   <td align=left bgColor="#EFEFEF">
				<span class="style5"><font color="#669966">&nbsp;</span>
		   </td>
		   <td align=center bgColor="#EFEFEF">
				<span class="style5"><font color="#669966"></span>
		   </td>
		   <td align=center bgColor="#EFEFEF">
				<span class="style5"><font color="#669966"></span>
		   </td>
	  </tr>
	<%
	}

%>
</table>

<br>
<form name="form1" method="post" enctype="multipart/form-data" >
	<table width="70%">
	<TR>
	<TD>  
		<input type="file" name="file11" size=20 >                                        <!--上传得新文件-->
		<%if(have){%><input type="button" value="上传" onclick="upload();"><%}%>
		<input type=hidden name="txt_file11" size=20 >                                    
		<input type=hidden name="txt_name11" value="">                                  
		<input type=hidden name="strfile"   value="<%=strfile%>">                         
		<input type=hidden name="strname"   value="<%=strname%>">                        
		<input type=hidden name=strsize  value="<%=strsize%>">
		<input type=hidden name=cursize  value="<%=cursize%>">
		<input type=hidden name=onesize  value="<%=onesize%>">
	</td>
	<td align=center width="20%">
		<input name="send"  type="button" value="完成" class=button1 onclick="ok()">
	</td>
	</TR>
	</table>
<hr width="70%" size=1>
</form>

<TABLE width=70% border=0 cellspacing=0 cellpadding=3 style="border-collapse: collapse">
	<TBODY>
	  <tr>
		  <td>
			  <span class="style5"><B><font color="#669966">&nbsp;&nbsp;说明:</font></B></span>
		  </td>
	  </tr>
	  <tr>
		  <td>
			  <span class="style6"><font color="#669966">1.最多能上传的文件数为:<%=count%>个</font></span>
		  </td>
	  </tr>
	  <tr>
		  <td>
			  <span class="style6"><font color="#669966">2.能上传的总文件大小为:<%=ds.toMKByte(Long.parseLong(sumsize))%></font></span>
		  </td>
	  </tr>
	  <tr>
		  <td>
			  <span class="style6"><font color="#669966">3.每个文件最大不能超过:<%=ds.toMKByte(Long.parseLong(onesize))%></font></span>
		  </td>
	  </tr>
	</tbody>
</table>
<br>
</fieldset>
</body>
</html>
<script>

	//上传单个文件
	function upload()
	{		
		document.all.txt_file11.value = document.all.file11.value;
		if(document.all.file11.value=="")
			return false;
		
		//取新上传的文件后缀
		var name1 = document.all.txt_file11.value;
		var i = name1.lastIndexOf(".");
		name1 = name1.substring(i);


		//取原文件名
		var name2=document.all.file11.value;
		var j=name2.lastIndexOf("\\");
		name2=name2.substring(j+1);


		if(document.all.strname.value=="")
		{	
			document.all.txt_file11.value=name2;
		}
		else
		{		
			document.all.txt_file11.value=name2;
			
		}
		
		document.all.form1.action="upfile.jsp?onesize=<%=onesize%>&strfile=<%=strfile%>&strname=<%=strname%>&cursize=<%=cursize%>&strsize=<%=strsize%>&sumsize=<%=sumsize%>&upmonth=<%=upmonth%>&count=<%=count%>&savedir=<%=savedir%>&txt_file11="+document.all.txt_file11.value;
		document.all.form1.submit();
	}

	//完成上传
	function ok()
	{
		var strfile=document.all.strfile.value;
		var strname=document.all.strname.value;
		var strsize=document.all.strsize.value;
		var cursize=document.all.cursize.value;
		var onesize=document.all.onesize.value;
		if(strname.charAt(0)==','){
			strname=strname.substring(1,strname.length);
			strfile=strfile.substring(1,strfile.length);
			strsize=strsize.substring(1,strsize.length);
		}

		opener.document.all.strfile.value=strfile;
		opener.document.all.strname.value=strname;
		opener.document.all.strsize.value=strsize;
		opener.document.all.cursize.value=cursize;
		opener.document.all.onesize.value=onesize;
		opener.document.all.form1.action=opener.document.all.form1.goto.value;

		if(opener.document.all.form1.goto.value!="")
			opener.document.all.form1.submit();
		window.close();
	}

	//删除文件
	function del(str,delsize)
	{
		var where = "delfile.jsp?onesize=<%=onesize%>&delsize="+delsize+"&delfile="+str+"&strfile=<%=strfile%>&strname=<%=strname%>&cursize=<%=cursize%>&strsize=<%=strsize%>&sumsize=<%=sumsize%>&upmonth=<%=upmonth%>&savedir=<%=savedir%>&count=<%=count%>";
		window.location = where;
	}

	err = "<%=err%>";
	if(err!=null&err!="null")
	{
		if(err=="1")alert("该文件超过规定大小,不能上传!");
		else if(err=="2")alert("该文件将超过总空间,不能上传!");
	}
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -