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

📄 upload.jsp

📁 Java 实现代码后台管理功能的 script语言
💻 JSP
📖 第 1 页 / 共 2 页
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="com.jspsmart.upload.*"%>
<%@ page import="net.fiyu.edit.RemotePic"%>
<jsp:useBean id="date" scope="page" class="net.fiyu.edit.TimeStamp"/>
<%@ page import="net.fiyu.edit.UploadWebHelper,net.fiyu.edit.UploadBean"%>

<%!
// 参数变量
String sType, sStyleName;
//' 设置变量
String sAllowExt, sUploadDir,sBaseUrl,sContentPath;
int  nAllowSize;
//' 接口变量
String sFileExt,sSaveFileName,sOriginalFileName,sPathFileName,FileName, nFileNum,realpatha;
String sAction;
Connection connect = null;
%>
<%!
/*' ============================================
' 去除Html格式,用于从数据库中取出值填入输入框时
' 注意:value="?"这边一定要用双引号
' ============================================*/
public String inHTML(String str)
{
	String sTemp;
	sTemp = str;
	if(sTemp.equals(""))
	{
		System.exit(0);
	}
	sTemp = sTemp.replaceAll("&", "&amp;");
	sTemp = sTemp.replaceAll("<", "&lt;");
	sTemp = sTemp.replaceAll(">", "&gt;");
	sTemp = sTemp.replaceAll("\"", "&quot;");
	return sTemp;
}
//初始化上传限制数据
public void InitUpload(String realpath){
	UploadWebHelper uw = new UploadWebHelper();
	uw.filename = realpath+"WEB-INF/style.xml";
	uw.getInstance();
	UploadBean bean = uw.InitPara();
	try{

       Calendar calendar = Calendar.getInstance();
	 /*realpatha="/"+calendar.get(Calendar.YEAR)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.DAY_OF_MONTH)+"/"+"upload/";
	//图片和新闻同步,并且将图片存放在UPLOAD下面
	//动态的创建UPLOAD目录
	//java.io.File file=new java.io.File("c:\\aa.txt");
	         java.io.File picStoreDir=new java.io.File(realpatha);
			   //do java.io.File.mkdirs()
				picStoreDir.mkdirs();

*/

//此处设置上传文件保存路径,注意路径要由ROOT开始=========================
sUploadDir =realpath+"/www/DT_UploadFile/"+calendar.get(Calendar.YEAR) + 
	"/"+ (calendar.get(Calendar.MONTH)+1) +"/"+ calendar.get(Calendar.DAY_OF_MONTH)+"/";
//修改此处需修改WEB-INF/Style.xml文件对应处<suploaddir>/UploadFile/</suploaddir>=========
//修改此处需修改eWebEditor.jsp文件对应处=========www.ITstudy.cn=========

     //sUploadDir = realpath+"articlemanage/article/";

		//sUploadDir = bean.getSuploaddir();
		//sUploadDir = realpatha;
        //System.out.println(sUploadDir);
		if(sType.equalsIgnoreCase("remote"))
		{
			sAllowExt =  bean.getSremoteext();
                        sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
			nAllowSize =  Integer.parseInt(bean.getSremotesize()) ;
                        System.out.println(sAllowExt+nAllowSize);
		}
                else if(sType.equalsIgnoreCase("file"))
               {
			sAllowExt = bean.getSfileext();
                        sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
			nAllowSize = Integer.parseInt(bean.getSfilesize());
                        System.out.println(sAllowExt+nAllowSize);
               }
               else if(sType.equalsIgnoreCase("media"))
		{
			sAllowExt =  bean.getSmediaext();
                        sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
			nAllowSize = Integer.parseInt(bean.getSmediasize());
                        System.out.println(sAllowExt+nAllowSize);
		}
                else if(sType.equalsIgnoreCase("flash"))
                {
			sAllowExt =  bean.getSflashext();
                        sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
			nAllowSize = Integer.parseInt(bean.getSflashsize());
                        System.out.println(sAllowExt+nAllowSize);
                }
		else
                {
			sAllowExt =  bean.getSimageext();
                        sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
			nAllowSize = Integer.parseInt(bean.getSimagesize());
                        System.out.println(sAllowExt+nAllowSize);
                }
	}
	catch(Exception e){
        }
}
%>
<%
//设置类型
sType=request.getParameter("type");
if(sType==null)
{
sType="image";
}
else
sType=request.getParameter("type").trim();
//设置样式
sStyleName=request.getParameter("style");
if (sStyleName==null)
{
  sStyleName="standard";
}
else
sStyleName=request.getParameter("style").trim();
//设置动作
sAction=request.getParameter("action");
if(sAction==null)
{
  sAction="sun";
}
else
sAction=request.getParameter("action").trim();
%>
<%
//初始化上传变量
InitUpload(config.getServletContext().getRealPath("/"));
//断开数据库连接
//sAction = UCase(Trim(Request.QueryString("action"))
if(sAction.equalsIgnoreCase("remote"))
{    //远程自动获取
	String sContent;
		String RemoteFileurl=null;
	String Protocol,sUrl;
	int Port;
	String LocalFileurl=null;
	String SrcFileurl=null;
	String SaveFileName=null;
	sContent=request.getParameter("eWebEditor_UploadText");
    if(sContent==null)
	{
		sContent="sunshanfeng";
	}
	else
		sContent=request.getParameter("eWebEditor_UploadText");
	System.out.println();
	System.out.println();
	System.out.println();
	System.out.println();
    System.out.println("替换前的html标记为:"+"\n"+sContent);
	if(sAllowExt!="")
	{
	Pattern pRemoteFileurl = Pattern.compile("((http|https|ftp|rtsp|mms):(//|\\\\){1}(([A-Za-z0-9_-])+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\\S*/)((\\S)+[.]{1}("+sAllowExt+")))");//取得网页上URL的正则表达式
    Matcher mRemoteFileurl = pRemoteFileurl.matcher(sContent);//对传入的字符串进行匹配
	Protocol=request.getProtocol();//取得通讯的协议
	String ProtocolA[]=Protocol.split("/");//取得协议前面的字母,如HTTP/1.1,变为"HTTP","1.1"
	sUrl = ProtocolA[0]+"://"+request.getServerName();//取得本地URL路径,如http://localhost
	//ProtocolA[]=null;
	Port=request.getServerPort();//取得端口值
	if(Port!=80)
	{//查看端口是否为80,如果不是还需要在联接上加上端口
     sUrl=sUrl+":"+Port;
	}
	String context=request.getContextPath();
	sUrl=sUrl+context+"/"+sUploadDir;
	System.out.println(sUrl);
	StringBuffer sb=new StringBuffer();
	boolean result=mRemoteFileurl.find();
	int i=0;

       while(result)
			{

             i++;
             RemoteFileurl=mRemoteFileurl.group(0);
			 System.out.println();
			 System.out.println();
			 System.out.println();
			 System.out.println();
			 System.out.println("需要替换的远程连接:"+"\n"+RemoteFileurl);
			 sOriginalFileName=RemoteFileurl.substring(RemoteFileurl.lastIndexOf("/"));
			 Pattern pFileType=Pattern.compile("[.]{1}("+sAllowExt+")");//二次匹配取得文件的类型
			 Matcher mFileType=pFileType.matcher(RemoteFileurl);
			 while(mFileType.find())
				{
				 String SaveFileType=mFileType.group();
				 LocalFileurl=sUploadDir+(String)date.Time_Stamp()+i+SaveFileType;//文件的路径,以时间戳命名
				}

			   String LoadFile=sUploadDir.substring(0,sUploadDir.length()-1);	SaveFileName=config.getServletContext().getRealPath("/")+LoadFile+LocalFileurl.substring(LocalFileurl.lastIndexOf("/")+1);
			   System.out.println();

⌨️ 快捷键说明

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