前端easyui也可以彻底做到前后端分离

这篇博客介绍了如何在前端框架EasyUI中实现彻底的前后端分离,通过实例展示了在Eclipse环境下,即使后台无数据,前端页面也能灵活切换。提供了一段首页代码示例,供开发者直接应用。
摘要由CSDN通过智能技术生成

前端框架easyui,在eclipse里后台无数据页面可以切换自如。直接上首页代码,复制粘贴就可以用。

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>客户关系管理系统主页</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	var url;

	function openTab(text, url, iconCls) {
		if ($("#tabs").tabs("exists", text)) {
			$("#tabs").tabs("select", text);
		} else {
			var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:100%' src='${pageContext.request.contextPath}/page/"
					+ url + "'></iframe>";
			$("#tabs").tabs("add", {
				title : text,
				iconCls : iconCls,
				closable : true,
				content : content
			});
		}
	}

	function openPasswordModifyDialog() {
		$("#dlg").dialog("open").dialog("setTitle", "修改密码");
		url = "${pageContext.request.contextPath}/user/modifyPassword.do?id=${currentUser.id}";
	}

	function closePasswordModifyDialog() {
		$("#dlg").dialog("close");
		$("#oldPassword").val("");
		$("#newPassword").val("");
		$("#newPassword2").val("");
	}

	function modifyPassword() {
		$("#fm").form("submit", {
			url : url,
			onSubmit : function() {
				var oldPassword = $("#oldPassword").val();
				var newPassword = $("#newPassword").val();
				var newPassword2 = $("
Sure, I can help you with that. Here's an example of how you can upload a PHPExcel file to a MySQL database using a front-end framework like EasyUI in a separate front-end and back-end setup. First, let's start with the front-end code using EasyUI to handle the file upload: ```html <!DOCTYPE html> <html> <head> <title>Excel Upload</title> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/easyui@1.9.25/themes/default/easyui.css"> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/easyui@1.9.25/jquery.easyui.min.js"></script> </head> <body> <h2>Excel Upload</h2> <form id="excelForm" method="post" enctype="multipart/form-data"> <input id="excelFile" name="excelFile" type="file"> <button id="uploadBtn" class="easyui-linkbutton" type="submit">Upload</button> </form> <script type="text/javascript"> $(function(){ $('#excelForm').form({ url: 'upload.php', onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ $.messager.show({ title: 'Success', msg: result, timeout: 5000 }); } }); }); </script> </body> </html> ``` Next, let's create the `upload.php` file on the server side to handle the file upload and database insertion: ```php <?php // Include PHPExcel library require_once 'PHPExcel/PHPExcel.php'; // Database connection details $host = 'localhost'; $username = 'your_username'; $password = 'your_password'; $database = 'your_database'; // File upload directory $targetDir = 'uploads/'; // Create target directory if it doesn't exist if (!is_dir($targetDir)) { mkdir($targetDir, 0777, true); } // Handle file upload $targetFile = $targetDir . basename($_FILES["excelFile"]["name"]); move_uploaded_file($_FILES["excelFile"]["tmp_name"], $targetFile); // Read the uploaded file using PHPExcel $objPHPExcel = PHPExcel_IOFactory::load($targetFile); $worksheet = $objPHPExcel->getActiveSheet(); // Database connection $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Loop through each row in the worksheet foreach ($worksheet->getRowIterator() as $row) { $rowData = []; $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // Loop through each cell in the row foreach ($cellIterator as $cell) { $rowData[] = $cell->getValue(); } // Insert row data into the database $sql = "INSERT INTO your_table_name (column1, column2, column3) VALUES (?, ?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param("sss", $rowData[0], $rowData[1], $rowData[2]); $stmt->execute(); } // Close database connection $conn->close(); // Delete the uploaded file unlink($targetFile); echo "Upload successful!"; ?> ``` Make sure to create a directory named "uploads" in the same directory as the `upload.php` file to store the uploaded files. Replace `'your_username'`, `'your_password'`, `'your_database'`, and `'your_table_name'` with your actual database credentials and table name. This is a basic example to get you started. You may need to modify it based on your specific requirements and validations. Additionally, make sure to sanitize and validate user input to prevent any security vulnerabilities. I hope this helps you with uploading PHPExcel files to a MySQL database using a front-end framework like EasyUI in a separate front-end and back-end setup. Let me know if you have any further questions!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值