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

📄 folderservlet.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *  FolderServlet.java
 */

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Liyan
 */

//The class hand the Http request
public class FolderServlet extends HttpServlet {


    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		
		HtmlOut htmlOut = new HtmlOut (response);

		Person p=new Person();
		p.setName (CommonMethods.GetUserName(request));
		String pass = CommonMethods.GetUserPass (request);
		if( p.getName ()==null || (!p.checkPassword(pass)) )
		{
	    	htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请先登录!","Login?action=reLog");
			htmlOut.outHtml();
			return;
		}

		//基本参数:
		String sBasePath=CommonMethods.GetUserFolderdir()+p.getName();
		String flag=request.getParameter("flag");
		String sFolderPath=request.getParameter("folder");
		String sIntoPath=request.getParameter("into");
		String relativePath="";
		if(sFolderPath!=null)
			relativePath=sFolderPath;
		if(sIntoPath!=null)
			relativePath=sIntoPath;
		relativePath=CommonMethods.DealWithGBCodeOfRequest(relativePath);
		String sPath=sBasePath+relativePath;
		String sDownload=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("download"));
		if(sDownload!=null){
			flag="download";
		}
		FolderChannel folderChannel=new FolderChannel();
		
		//response.setBufferSize(0);
		System.out.println (flag);
		if (flag==null)
		{
		//取得文件夹主模板:
			TemplateList tempList=CommonMethods.getFolder_MainTemplate();
			folderChannel.makeFolder_Main(p,tempList,htmlOut,relativePath,"");
		} else {
					
			if (flag.compareTo("addfolder")==0) //添加目录界面
			{
				String sFolder=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("folder"));
				String sHtmlOut="";
				sHtmlOut+="<tr bgcolor=\"#FFFFFF\"> <td colspan=\"6\">";
				sHtmlOut+="<form name=ok action=\"FolderServlet?flag=doaddfolder\" method=\"POST\"";
				sHtmlOut+=" onsubmit=\"return checkadd(this)\">";
				sHtmlOut+="<input name=folder type=hidden value='"+sFolder+"'>";
				sHtmlOut+="<table border=0 cellspacing=0 cellpadding=0 width=100%>";
				sHtmlOut+="<tr>";
				sHtmlOut+="<td nowrap width=20% align=center><font color=0000aa>目录名称:</font></td>";
				sHtmlOut+="<td nowrap width=60%><input type=text name=name size=45 MAXLENGTH=100></td>";
				sHtmlOut+="<td nowrap width=20%><input type=submit value=\"添加\">";
				sHtmlOut+="<input type=reset value=重置 name=\"reset\"></form>";
				sHtmlOut+="</div></td></tr></table></td></tr>";
				sHtmlOut+="";


				TemplateList tempList=CommonMethods.getFolder_MainTemplate();
				folderChannel.makeFolder_Main(p,tempList,htmlOut,relativePath,sHtmlOut);
				//response.sendRedirect("FolderServlet");
			}
			
			if (flag.compareTo("doaddfolder")==0) //添加目录动作
			{
				String sFolder=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("name"));
				System.out.println("folder name:"+sFolder); 
				System.out.println(sPath+""+File.separatorChar +""+sFolder);
				Folder myFolder = new Folder(sPath+""+File.separatorChar +""+sFolder);
				myFolder.mkDirection();
				myFolder=null;
				//response.sendRedirect("FolderServlet?into="+relativePath);
				//htmlOut.addString("添加 "+sFolder+" 成功!<br>");
				//htmlOut.addString("<a href='FolderServlet?into="+relativePath+"'>返回</a>");
				
				//用Jscript代替sendRedirect
				String sTmp="";
				sTmp+="<script language=\"Javascript\">";
				sTmp+="location='FolderServlet?into="+this.makeStr(relativePath)+"';";
				sTmp+="</script>";
				htmlOut.addString(sTmp);
			}
			
			/*if (flag.compareTo("up")==0) //返回上层目录
			{
				Folder myFolder = new Folder(sPath);
				if(myFolder.getPath().compareTo(sBasePath)==0){
					myFolder=null;
					response.sendRedirect("FolderServlet");
				}
				else{
					String sTmp=myFolder.getParent();
					sTmp=sTmp.substring(sBasePath.length());
					response.sendRedirect("FolderServlet?into="+sTmp);
				}
				
			}*/
			
			if (flag.compareTo("edit")==0) //编辑界面
			{
				int nLength=request.getParameterValues("single").length;
				String[] dArray=new String[nLength];
				String sFile="";
				dArray=request.getParameterValues("single");
				if(dArray[0].compareTo("--88ZYZ88--")==0)
					sFile=CommonMethods.DealWithGBCodeOfRequest(dArray[1]);
				else
					sFile=CommonMethods.DealWithGBCodeOfRequest(dArray[0]);
				String sHtmlOut="";
				sHtmlOut+="<tr bgcolor=\"#FFFFFF\"><td colspan=\"5\">";
				sHtmlOut+="<form name=ok action=\"FolderServlet?flag=doedit\" method=\"POST\"";
				sHtmlOut+=" onsubmit=\"return checkedit(this)\">";
				sHtmlOut+="<input type=hidden name=into value='"+relativePath+"'>";
				sHtmlOut+="<input type=hidden name=oldname value='"+sFile+"'>";
				sHtmlOut+="<table border=0 cellspacing=0 cellpadding=0 width=100%>";
				sHtmlOut+="<tr>";
				sHtmlOut+="<td nowrap width=20% align=center><font color=0000aa>修改名称:</font></td>";
				sHtmlOut+="<td nowrap width=60%><input type=text name=newname size=45 MAXLENGTH=100 Value='"+sFile+"'></td>";
				sHtmlOut+="<td nowrap width=20%><input type=submit value=\"修改\">&nbsp;<input type=button Value=返回 onclick=history.back()></td></form>";
				sHtmlOut+="</div></td></tr></table></td></tr>";
				sHtmlOut+="";


				TemplateList tempList=CommonMethods.getFolder_MainTemplate();
				folderChannel.makeFolder_Main(p,tempList,htmlOut,relativePath,sHtmlOut);
			}
			
			if (flag.compareTo("doedit")==0) //编辑功能
			{
				String sOld=""+File.separatorChar +""+CommonMethods.DealWithGBCodeOfRequest(request.getParameter("oldname"));
				String sNew=""+File.separatorChar +""+CommonMethods.DealWithGBCodeOfRequest(request.getParameter("newname"));
				Folder myFolder = new Folder(sBasePath+relativePath+sOld);
				myFolder.renameTo(sBasePath+relativePath+sNew);
				myFolder = null;
				//response.sendRedirect("FolderServlet?into="+relativePath);
				//htmlOut.addString("修改成功!<br>");
				//htmlOut.addString("<a href='FolderServlet?into="+relativePath+"'>返回</a>");
				
				//用Jscript代替sendRedirect
				String sTmp="";
				sTmp+="<script language=\"Javascript\">";
				sTmp+="location='FolderServlet?into="+this.makeStr(relativePath)+"';";
				
				sTmp+="</script>";
				htmlOut.addString(sTmp);
			}
			
			if (flag.compareTo("delete")==0) //删除文件或目录
			{
				int nLength=request.getParameterValues("single").length;
					String[] dArray=new String[nLength];
					dArray=request.getParameterValues("single");
					for(int i=0;i<nLength;i++) {
						if(dArray[i]!=null&&(dArray[i].compareTo("--88ZYZ88--")!=0)){
							dArray[i]=CommonMethods.DealWithGBCodeOfRequest(dArray[i]);
							Folder tmpFolder = new Folder(sBasePath+relativePath+""+File.separatorChar +""+dArray[i]);
							tmpFolder.deltree(sBasePath+relativePath+""+File.separatorChar +""+dArray[i]);
							//out.println (sBasePath+relativePath+""+File.separatorChar +""+dArray[i]);
							tmpFolder=null;
						}
					}
					//response.sendRedirect("FolderServlet?into="+relativePath);
					//htmlOut.addString("删除成功!<br>");
					//htmlOut.addString("<a href='FolderServlet?into="+relativePath+"'>返回</a>");
					
					//用Jscript代替sendRedirect
					String sTmp="";
					sTmp+="<script language=\"Javascript\">";
					sTmp+="location='FolderServlet?into="+this.makeStr(relativePath)+"';";
					
					sTmp+="</script>";
					htmlOut.addString(sTmp);
			}
			
			if (flag.compareTo("upload")==0) //上载界面
			{
				String sHtmlOut="";
				
				sHtmlOut+="<tr bgcolor=\"#E3E5E5\">";
				sHtmlOut+="<td colspan=\"4\"><div align=\"center\">";
				sHtmlOut+="<form name=ok enctype=\"multipart/form-data\" ";
				sHtmlOut+="method=post onsubmit=\"return checkupload(this)\">";
				sHtmlOut+="<input name=into type=hidden value='"+relativePath+"'>";
				sHtmlOut+="请选择您要上载的内容:<br>";
				sHtmlOut+="<input name=\"file\" type=file accept=\"*.*\"><br>";
				sHtmlOut+="<input type=submit value=\"上载\">";
				sHtmlOut+="</form></div></td><td width=\"20\">&nbsp;</td>";

				TemplateList tempList=CommonMethods.getFolder_MainTemplate();
				folderChannel.makeFolder_Main(p,tempList,htmlOut,relativePath,sHtmlOut);
			}
			
			if (flag.compareTo("download")==0) //下载功能
			{
				
				htmlOut.addString(sDownload);
				htmlOut.outHtml();
				response.sendRedirect("DownloadServlet/"+sDownload+"?download="+sDownload);
			}

			
		}
		htmlOut.outHtml();
    }
	
	public String makeStr(String sTmp){
		int nB=0,nE=sTmp.indexOf(""+File.separatorChar +"");
		String sOk="";
		while(nE!=-1){
			sOk+=sTmp.substring(nB,nE+1)+""+File.separatorChar +"";
			nB=nE+1;
			nE=sTmp.indexOf(""+File.separatorChar +"",nB);
		}
		sOk+=sTmp.substring(nB,sTmp.length());
		return sOk;
	}
	
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }
}

⌨️ 快捷键说明

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