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

📄 upload.jsp

📁 本代码是一个权限管理系统源代码
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312"%>


<%@ page import="com.seavision.PermissionManage.upload.*"%>
<%@ page import="com.seavision.PermissionManage.help.*"%>


<%@ page import="com.seavision.PermissionManage.components.*"%>

<%@ page import="com.seavision.PermissionManage.vo.*"%>

<%
         String url = "";                                                                                                      
			String ipAddress = ""; // ip地址                                                                                      
			String operator = ""; // 操作人                                                                                       
			String message = "";                                                                                                  
			                                                                                                                      
	                                                                                                   
			// 从session获取参数                                                                                                  
			                                                                                                                      
			UserLoginVO userVO = (UserLoginVO) session.getAttribute("userLoginVO");                                               
			operator = userVO.getUserName();                                                                                      
			 url = request.getRequestURI();;                                                                                      
			ipAddress = request.getRemoteAddr();                                                                                  
			                                                                                                 
				// 判断用户权限                                                                                       
			                                                                                             
		                                                                                                                              
					                                                                                         
					// 判断url是否为null                                                                                  
					if (url==null||url.trim()=="") {                                                                      
						message = "url不能为空!";                                                                    
						out.println(message.toString());                                                              
						%>                                                                                            
		 <input type="button" name="Submit" value="返回" onclick="javascript:location.href='functionManage.jsp'"/>                    
		<%                                                                                                                            
					}                                                                                                     
					// 判断ip地址不能为空                                                                                 
					if (ipAddress==null||ipAddress.trim()=="") {                                                          
						message = "ip地址不能为空!";                                                                 
						out.println(message.toString());                                                              
						%>                                                                                            
		 <input type="button" name="Submit" value="返回" onclick="javascript:location.href='functionManage.jsp'"/>                    
		<%                                                                                                                            
					}                                                                                                     
					// 判断操作人不能为空                                                                                 
					if (operator==null||operator.trim()=="") {                                                            
						message = "操作人不能为空!";                                                                 
						out.println(message.toString());                                                              
						%>                                                                                            
		 <input type="button" name="Submit" value="返回" onclick="javascript:location.href='functionManage.jsp'"/>                    
		<%                                                                                                                            
					}                                                   
          
            boolean commit = true;
			try {
				//进行事物处理	
				HibernateUtil.beginTransaction();
			} catch (net.sf.hibernate.HibernateException e) {
				e.printStackTrace();
			}

			//进行数据连接
			FunctionManage fm = DaoFectory.getFunctionManage();
			//		清除旧的数据库表

			fm.deleteFunction();
			
			//实例化上载bean
			SmartUpload mySmartUpload = new SmartUpload();
			//初始化
			mySmartUpload.initialize(pageContext);
			//设置上载的最大值
			mySmartUpload.setMaxFileSize(500 * 1024 * 1024);
			//上载文件
			mySmartUpload.upload();
			//循环取得所有上载的文件
			for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
				//取得上载的文件
				SmartFile myFile = mySmartUpload.getFiles().getFile(i);
				if (!myFile.isMissing()) {
					//取得上载的文件的文件名
					String myFileName = myFile.getFileName();
					
					//取得不带后缀的文件名
					String suffix = myFileName.substring(0, myFileName
							.lastIndexOf('.'));
					//取得后缀名
					String ext = mySmartUpload.getFiles().getFile(0)
							.getFileExt();
					//取得文件的大小 
					int fileSize = myFile.getSize();
					//保存路径
					String aa = getServletContext().getRealPath("/") + "jsp\\";
					String trace = aa + myFileName;
					//取得别的参数
					String explain = (String) mySmartUpload.getRequest()
							.getParameter("text");
					String send = (String) mySmartUpload.getRequest()
							.getParameter("send");
					//将文件保存在服务器端 
					myFile.saveAs(trace, mySmartUpload.SAVE_PHYSICAL);

					//将文件读到流中 
					java.util.List result = new java.util.ArrayList();
					java.io.File file = new java.io.File(trace);
					//System.out.println("文件明是===="+file);
					java.io.FileInputStream fis = new java.io.FileInputStream(
							file);
					java.io.InputStreamReader isr = new java.io.InputStreamReader(
							fis);
					java.io.BufferedReader br = new java.io.BufferedReader(isr);
					System.out.println(file.length());

					while (true) {
						//System.out.println("kjdfkjf");
						String str = br.readLine();
						System.out.println("kjdfkjf====" + str);
						if (str == null) {
							break;
						}
						String[] oneCode = str.split("=");
						if (oneCode == null || oneCode.length != 2) {
							continue;
						}
						String cs = oneCode[0].substring(0, oneCode[0]
								.lastIndexOf("/"));
						oneCode[0] = oneCode[0]
								.substring(cs.lastIndexOf("/") + 1);
						//System.out.println("ceshi--->"+oneCode[0]);
						oneCode[1] = oneCode[1].substring(0, oneCode[1]
								.length() - 1);
						//System.out.println("ceshi--->"+oneCode[1]);
						FunctionVO functionVo = new FunctionVO();
						functionVo.setFunctionName(oneCode[1]);
						functionVo.setUrl(oneCode[0]);
						//System.out.println("fun===="+functionVo.getUrl());
						result.add(functionVo);
					}
					br.close();
					//将内容写入数据库
					for (int j = 0; j < result.size(); j++) {
						FunctionVO functionvo = (FunctionVO) result.get(j);
						String str = fm.saveFunction(functionvo);
						//System.out.println("save====="+str);
						if (str != "success") {
							commit = false;
						}
					}
					try {
						//上传如果失败进行事物回滚
						HibernateUtil.endTransaction(commit);
					} catch (net.sf.hibernate.HibernateException e) {
						e.printStackTrace();
					}
                   		// 写入日志                                                                                           
					LogManage lm = DaoFectory.getLogManage();                                                             
					lm.addLog(operator, url, ipAddress, "UpLoad");   
					out.println(("上传成功!!!").toString());%>
<input type="button" name="Submit" value="返回" onclick="history.go(-1)" />
<%} else {
				out.println(("上传失败!!!请选择上传的文件名及路径!!!!").toString());

				%>
<input type="button" name="Submit" value="返回" onclick="history.go(-1)" />
<%
     }
			}//与前面的if对应

		%>

⌨️ 快捷键说明

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