最新版web 配置平台页面
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最新版web 配置平台页面相关的知识,希望对你有一定的参考价值。
修改点:1、搜索更新
2、点击搜索的文件,使用ajax读取文件内容显示页面上
3、保存文件使用ajax方式,保存需要获取页面得值,新增getFromValue()方法,用来统一获取页面得值,并封装成json
1.1configurationAction.java
package com.hkwx.controll; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSONObject; import com.hkwx.manager.ExcelHelper; import com.hkwx.manager.FileOperateUtil; import cn.com.hikvision.www.datacenter.pxe_server.wsdl.PxeConfigFileContent; @Controller public class configurationAction { // private pxeClient client = new pxeClient("127.0.0.1"); // private PxeUpgradeStatus upgrade; // 展示首页 @RequestMapping("/page/configurationPlatform") public ModelAndView login(ModelAndView mv) throws Exception { mv.setViewName("/configurationPlatform"); return mv; } //导入excel @RequestMapping("/page/importExcel") public void importExcel(ModelAndView mv, HttpServletRequest request,HttpServletResponse response) throws Exception { init(request); mv.setViewName("/managePlatfrom"); String filePath = ""; try { filePath = FileOperateUtil.upload(mv,request); } catch (Exception e) { } if (!filePath.equals("")) { //获取字段值 HashMap<String, String> map = ExcelHelper.readProperties(new File(filePath)); PxeConfigFileContent pxeConfigFileContent= new PxeConfigFileContent(); //是用反射,将值放进去 Class FileContent =pxeConfigFileContent.getClass(); Field[] Fields = FileContent.getDeclaredFields(); for (String key : map.keySet()) { Field field = FileContent.getDeclaredField(key); field.setAccessible(true); if(field.getType().getName().equals("int")){ field.set(pxeConfigFileContent,(int)Double.parseDouble(map.get(key))); continue; } if(field.getType().getName().equals("cn.com.hikvision.www.datacenter.pxe_server.wsdl.PxeRaidCardStatus")){ continue; } if(field.getType().getName().equals("cn.com.hikvision.www.datacenter.pxe_server.wsdl.PxeSFPCardStatus")){ continue; } else{ field.set(pxeConfigFileContent,map.get(key)); continue; } } String str = JSONObject.toJSONString(pxeConfigFileContent); JSONObject json = JSONObject.parseObject(str); responseAjax(response, json); } } //修改文件 @RequestMapping("/page/save") public void save(ModelAndView mv,HttpServletRequest request,HttpServletResponse response) throws Exception { mv.setViewName("/managePlatfrom"); String message = FileOperateUtil.saveFile(request); //将执行的信息返回给ajax responseAjax(response, message); } //创建 @RequestMapping("/page/create") public void create(ModelAndView mv,HttpServletRequest request,HttpServletResponse response) throws Exception { //获取当前登录的用户名 String message = FileOperateUtil.create(request); responseAjax(response, message); } //导出,另存为 @RequestMapping("/page/download") public void download(ModelAndView mv,HttpServletRequest request,HttpServletResponse response) throws Exception { try { String downloadfFileName = request.getParameter("filename"); downloadfFileName = new String(downloadfFileName.getBytes("iso-8859-1"),"utf-8"); String fileName = downloadfFileName.substring(downloadfFileName.indexOf("_")+1); String userAgent = request.getHeader("User-Agent"); byte[] bytes = userAgent.contains("MSIE") ? fileName.getBytes() : fileName.getBytes("UTF-8"); fileName = new String(bytes, "ISO-8859-1"); response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", fileName)); FileOperateUtil.download(downloadfFileName, response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } } //搜索 @RequestMapping("/page/search") public void search(ModelAndView mv,HttpServletRequest request,HttpServletResponse response) throws Exception { FileOperateUtil.search(request,response); } //读取文件内容 @RequestMapping("/page/readFile") public void readFile(ModelAndView mv,HttpServletRequest request,HttpServletResponse response) throws Exception { PxeConfigFileContent pxeConfig = FileOperateUtil.readFile(mv,request); String str = JSONObject.toJSONString(pxeConfig); JSONObject json = JSONObject.parseObject(str); responseAjax(response, json); } //初始化请求 获取上传的路径 private void init(HttpServletRequest request) { if (FileOperateUtil.FILEDIR == null) { FileOperateUtil.FILEDIR = request.getSession().getServletContext().getRealPath("/") + "file/"; } } public void responseAjax(HttpServletResponse response, Object message) { response.setContentType("application/json"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setCharacterEncoding("UTF-8"); PrintWriter out = null; try { out = response.getWriter(); } catch (IOException e) { e.printStackTrace(); } out.print(message); out.flush(); out.close(); } }
1.2 ExcelHelper.java
package com.hkwx.manager; /** * Jun 25, 2012 */ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Properties; import org.apache.commons.io.FilenameUtils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; /** * Excel组件 * * @author Snowolf * @version 1.0 * @since 1.0 */ public abstract class ExcelHelper { /** * Excel 2003 */ private final static String XLS = "xls"; /** * Excel 2007 */ private final static String XLSX = "xlsx"; /** * 分隔符 */ private final static String SEPARATOR = "|"; /** * 由Excel文件的Sheet导出至List * * @param file * @param sheetNum * @return */ public static List<String> exportListFromExcel(File file, int sheetNum) throws IOException { return exportListFromExcel(new FileInputStream(file), FilenameUtils.getExtension(file.getName()), sheetNum); } /** * 由Excel流的Sheet导出至List * * @param is * @param extensionName * @param sheetNum * @return * @throws IOException */ public static List<String> exportListFromExcel(InputStream is, String extensionName, int sheetNum) throws IOException { Workbook workbook = null; if (extensionName.toLowerCase().equals(XLS)) { workbook = new HSSFWorkbook(is); } else if (extensionName.toLowerCase().equals(XLSX)) { workbook = new XSSFWorkbook(is); } return exportListFromExcel(workbook, sheetNum); } /** * 由指定的Sheet导出至List * * @param workbook * @param sheetNum * @return * @throws IOException */ private static List<String> exportListFromExcel(Workbook workbook, int sheetNum) { Sheet sheet = workbook.getSheetAt(sheetNum); // 解析公式结果 FormulaEvaluator evaluator = workbook.getCreationHelper() .createFormulaEvaluator(); List<String> list = new ArrayList<String>(); int minRowIx = sheet.getFirstRowNum()+1; int maxRowIx = sheet.getLastRowNum(); for (int rowIx = minRowIx; rowIx <= maxRowIx; rowIx++) { Row row = sheet.getRow(rowIx); StringBuilder sb = new StringBuilder(); short minColIx = row.getFirstCellNum(); short maxColIx = row.getLastCellNum(); for (short colIx = minColIx; colIx <= maxColIx; colIx++) { Cell cell = row.getCell(new Integer(colIx)); CellValue cellValue = evaluator.evaluate(cell); if (cellValue == null) { continue; } // 经过公式解析,最后只存在Boolean、Numeric和String三种数据类型,此外就是Error了 // 其余数据类型,根据官方文档,完全可以忽略http://poi.apache.org/spreadsheet/eval.html switch (cellValue.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: sb.append(SEPARATOR + cellValue.getBooleanValue()); break; case Cell.CELL_TYPE_NUMERIC: // 这里的日期类型会被转换为数字类型,需要判别后区分处理 if (DateUtil.isCellDateFormatted(cell)) { sb.append(SEPARATOR + cell.getDateCellValue()); } else { sb.append(SEPARATOR + cellValue.getNumberValue()); } break; case Cell.CELL_TYPE_STRING: sb.append(SEPARATOR + cellValue.getStringValue()); break; case Cell.CELL_TYPE_FORMULA: break; case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_ERROR: break; default: break; } } list.add(sb.toString()); } return list; } //读取cfg的全部信息 public static HashMap<String, String> readProperties(File file) { Properties props = new Properties(); HashMap<String, String> map = new HashMap<String, String>(); try { InputStream in = new BufferedInputStream (new FileInputStream(file)); props.load(in); Enumeration en = props.propertyNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); String Property = props.getProperty (key); map.put(key, Property); System.out.println(key+Property); } } catch (Exception e) { e.printStackTrace(); } return map; } public static void main(String[] args) { String path = "E:\\excel.xls"; List<String> list = null; HashMap<String, String> map = new HashMap<String, String>(); try { list = ExcelHelper.exportListFromExcel(new File(path), 0); for (int i = 0; i < list.size(); i++) { String temp[] = list.get(i).split("\\|"); map.put(temp[1],temp[2]); } } catch (IOException e) { } } }
1.3 FileOperateUtil.java
package com.hkwx.manager; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import cn.com.hikvision.www.datacenter.pxe_server.wsdl.PxeConfigFileContent; public class FileOperateUtil { public static String FILEDIR = null; /* private static pxeClient client = new pxeClient("127.0.0.1"); private PxeUpgradeStatus upgrade;*/ /** * 上传 * @param request * @throws IOException */ public static String upload(ModelAndView mv,HttpServletRequest request) throws IOException{ //获取请求 MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request; // MultipartFile multipartFile = mRequest.getFile("file"); //得到上传的文件路径 String fileName = multipartFile.getOriginalFilename(); //创建新的文件或文件夹 File file = new File(FILEDIR); //判断文件是否存在 if (!file.exists()) { file.mkdir(); } if(!"".equals(fileName)){ String filename = initFilePath(multipartFile.getOriginalFilename()); String[] fileArray = filename.split("\\\\"); String file1 = fileArray[fileArray.length-1]; mv.addObject("filename", file1); write(multipartFile.getInputStream(), new FileOutputStream(filename)); System.out.println("上传成功"); return filename; } return null; } private static String initFilePath(String name) { File file = new File(FILEDIR); if (!file.exists()) { file.mkdir(); } String filename = (file.getPath() + "\\"+ name).replaceAll(" ", "-"); return filename; } public static void download(String downloadfFileName, ServletOutputStream out) { try { //根据配置文件名获取内容 PxeGetConfigFileReq FileReq = new PxeGetConfigFileReq(downloadfFileName); PxeGetConfigFileRsp FileRsp = client.pxeGetConfigFile(FileReq); //当获取成功时 if(FileRsp.getStatusCode()==100){ PxeConfigFileContent pxeConfigFileContent= FileRsp.getContent(); //是用反射,获取所有对象的值 Class FileContent =pxeConfigFileContent.getClass(); Field[] fields = FileContent.getDeclaredFields(); HSSFWorkbook wb = new HSSFWorkbook();//创建工作薄 HSSFSheet sheet = wb.createSheet(downloadfFileName);//创建工作表,名称为fileName for (int i = 0; i < fields.length; i++) { Field f = fields[i]; HSSFRow row = sheet.createRow(i); //创建一行 createCell(row, 0, f.getName()); createCell(row, 1, (String)f.get(pxeConfigFileContent)); } FileOutputStream outputStream = new FileOutputStream(new File(downloadfFileName)); wb.write(outputStream); outputStream.flush(); outputStream.close(); }else{ } } catch (FileNotFoundException e) { } } //修改文件 public static String saveFile(HttpServletRequest request){ //获取当前登录的用户名 String user = (String) request.getSession().getAttribute("username"); // 获取前台json数据 String jsonObjValue = request.getParameter("jsonObjValue"); JSONObject json = JSONObject.parseObject(jsonObjValue); //从json String pv =json.getString("pv"); String pm = json.getString("pm"); PxeConfigFileContent FileContent = new PxeConfigFileContent(); // 给FileContent赋值 pxeConfig.setPv(pv); pxeConfig.setPm(pm); PxeGetConfigListReq FileReq = new PxeGetConfigListReq(); PxeGetConfigListRsp FileRsp = client.pxeGetConfigList(FileReq); List<PxeConfigFileInfo> PxeConfigFileInfoList= FileRsp.getConfiginfo(); //是否存在文件标示,0标不存在。1表示存在 int isExit = 0; //取所有配置文件 for (int i = 0; i < PxeConfigFileInfoList.size(); i++) { //获取配置文件名称 String fileName = PxeConfigFileInfoList.get(i).getBomname(); //如果文件存在 if(fileName.equals(bomname)){ //修改文件 PxeModifyConfigFileReq FileReq = new PxeModifyConfigFileReq(bomname, operator, FileContent); PxeModifyConfigFileRsp FileRsp = client.pxeModifyConfigFile(FileReq); isExit = 1; } } if(isExit==0){ return "配置文件不存在,请先创建配置文件"; }else{ return "文件保存成功"; } return "文件保存成功"; } /** * 创建文件 */ public static String create(HttpServletRequest request){ String bomname = request.getParameter("filename"); //获取前台所有参数 String cp2 = request.getParameter("cp"); String pm2 = request.getParameter("pm"); //创建文件 PxeCreateConfigFileReq FileReq = new PxeCreateConfigFileReq(bomname, operator, FileContent); PxeCreateConfigFileRsp FileRsp = client.pxeCreateConfigFile(FileReq); // 判断状态码 if(FileRsp.getStatusCode().eqlues("ok")){ return "创建成功"; }else{ return "创建失败"; // } } //创建列值 public static void createCell(HSSFRow row ,int flag,String value){ HSSFCell cell = row.createCell(flag); //创建一列 cell.setCellValue(value); } /** * 写入数据 * @param in * @param out * @throws IOException */ public static void write(InputStream in, OutputStream out) throws IOException{ try{ byte[] buffer = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } out.flush(); } finally { try { in.close(); } catch (IOException ex) { } try { out.close(); } catch (IOException ex) { } } } //搜索 public static void search(HttpServletRequest request,HttpServletResponse response){ PrintWriter pw = null; try { pw = response.getWriter(); } catch (IOException e) { e.printStackTrace(); } int defult = 20; int resultSize =20;//记录返回条数 PxeGetConfigListReq FileReq = new PxeGetCodnfigListReq(); PxeGetConfigListRsp FileRsp = client.pxeGetConfigList(FileReq); List<PxeConfigFileInfo> PxeConfigFileInfoList= FileRsp.getConfiginfo(); List<String> newlist = new ArrayList<String>(); String searchText = request.getParameter("condition"); String type = request.getParameter("type"); // //如果是点击事件,则返回所有查询结果 if(Integer.parseInt(type)==1){ resultSize = PxeConfigFileInfoList.size(); }else{//如果不是点击事件,判断查询结果长度是否大于20条,大于20条则只返回20条,小于20条则返回所有 resultSize = PxeConfigFileInfoList.size()>defult ? defult:PxeConfigFileInfoList.size(); } // if(searchText!=null) // for (int i = 0; i < newlist.size(); i++) { String fileName = PxeConfigFileInfoList.get(i).getBomname(); if(fileName.indexOf(searchText)>=0){ newlist.add(fileName); } } String jsonString = JSON.toJSONString(newlist, true); JSONArray json = JSONArray.parseArray(jsonString); pw.print(json); pw.flush(); pw.close(); } //读取文件 public static PxeConfigFileContent readFile(ModelAndView mv,HttpServletRequest request){ mv.setViewName("/managePlatfrom"); String fileName = request.getParameter("fileName"); //根据文件名获取文件内容 PxeGetConfigFileReq FileReq = new PxeGetConfigFileReq(fileName); PxeGetConfigFileRsp FileRsp = client.pxeGetConfigFile(FileReq); PxeConfigFileContent pxeConfigFileContent= FileRsp.getContent(); return pxeConfigFileContent; } }
1.4 configurationPlatform.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all"> <script src="js/jquery-1.11.3.min.js"></script> <script src="js/jquery-form.js"></script> <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> <base href="<%=basePath%>"> <title>My JSP ‘hello.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> </head> <body>> <div class="header"> <div class="container"> <div class="header-main"> <div class="clearfix"><h1 style="text-align: center;">PXE配置管理平台</h1> </div> </div> </div> </div> <div class="top-navg-main"> <div class="container"> <div class="top-navg"> <span class="menu"> <img src="images/icon.png" /></span> <ul class="res"> <li><a href="${pageContext.request.contextPath}/page/managePlatfrom" class="active hvr-sweep-to-bottom">配置平台</a></li> <li><a href="${pageContext.request.contextPath}/page/textPlatfrom" class="hvr-sweep-to-bottom" href="about.html">测试平台</a></li> <li><a href="${pageContext.request.contextPath}/page/montiorPlatfrom" class="hvr-sweep-to-bottom" href="services.html">监控平台</a></li> <li><a href="${pageContext.request.contextPath}/page/userPlatfrom" class="hvr-sweep-to-bottom" href="typo.html">用户管理</a></li> </ul> </div> </div> </div> <div class="top-navg-main" > <div class="container"> <div class="top-navg"> 配置平台页面 <div id = "seachAre"> <input name="searchText" id="searchText" type="text"> <input type="button" name="search" id="search" value=搜索"> <div id = "searchResult" style="border:1;"> </div> </div> <form action="page/importExcel"method="post" id ="form" enctype="multipart/form-data"> <div> <input type="file" class="file" name="file" id = "file" value ="${filename}"> </div> </form> <form action="page/save" method="post" id ="form2" > <!-- 保存显示 --> <input type = "text" value="${filename}" id ="filename2" > <table style="display: block;" id = "table1"> <tr><td> <span>cp:</span><span id ="cp"></span> </td></tr> <tr><td> <span>ct:</span><span id ="ct"></span> </td></tr> <tr><td> <span>pn:</span><span id ="pn"></span> </td></tr> <tr><td> <span>pm:</span><span id ="pm"></span> </td></tr> <tr><td> <span>pv:</span><span id ="pv"></span> </td></tr> </table> <!-- 修改显示 --> <table style="display:none;" id = "table2"> <tr><td> <span>mode:</span><input type ="text" id = "cp2" name="cp" ></input> </td></tr> <tr><td> <span>code:</span><input type ="text" id = "ct2" name="ct" ></input> </td></tr> <tr><td> <span>version:</span><input type ="text" id = "pn2" name="pn" ></input> </td></tr> <tr><td> <span>BMCversion:</span><input type ="text" id = "pm2" name="pm" ></input> </td></tr> <tr><td> <span>PCIDid:</span><input type ="text" id = "pv2" name="pv"></input> </td></tr> </table> <input type ="text" id = "filename" style="display: none;" name="filename"></input> <input type="button" id = "save" value="保存"> <input type="button" id = "modify" value="修改"> <input type="button" id = "create" value="创建"> <input type="button" onclick="javascript:window.location=‘page/download?filename=${filename}‘" value="导出"> </form> </div> </div> </div> <script type="text/javascript"> $(function(){ if(‘${message}‘!=""){ alert(‘${message}‘); } //给按钮绑定事件 bindEvent(); //执行查询事件 search(); }); function bindEvent(){ //创建文件 $("#create").click(function(){ var fileName = prompt(‘请输入文件名‘); $("#form2").ajaxSubmit({ type: "post", url: "page/create", data: {fileName:fileName}, dataType: "json", success: function(data){ alert(data); } }); }); //导入文件 $("#file").change(function(){ $("#form").ajaxSubmit({ type: ‘post‘, // 提交方式 get/post url: ‘page/importExcel‘, // 需要提交的 url dataType: "json", data: {}, success: function(data) { // data 保存提交后返回的数据,一般为 json 数据 // 此处可对 data 作相关处理 $("#cp").text(data.cp); $("#ct").text(data.ct); $("#pn").text(data.pn); $("#pm").text(data.pm); $("#pv").text(data.pv); $("#cp2").val(data.cp); $("#ct2").val(data.ct); $("#pn2").val(data.pn); $("#pm2").val(data.pm); $("#pv2").val(data.pv); } }); }); //保存文件 $("#save").click(function(){ var isNeed = confirm(‘是否进行保存‘); if(isNeed==true){ //获取页面的所有的值,我只写三个,其他的你自己写 var jsonObjValue = getFromValue(); var jsonString = JSON.stringify(jsonObjValue); $("#table1").show(); $("#table2").hide(); $.ajax({ type: "post", url: "page/save", data: {jsonObjValue:jsonString,name:"123"}, // 将值传到后台 dataType: "json", success: function(data){ alert(data); } }); } }); //当输入框的值改变时 $("#searchText").bind(‘input propertychange‘,function(){ search(); }); //修改文件 $("#modify").click(function(){ $("#table2").show(); $("#table1").hide(); }); //查找 $("#search").click(function(){ $("#searchResult").html(""); var text = $("#searchText").val(); $.ajax({ type: "post", url: "page/search", data: {condition:text,type:1}, //1表示点击事件 dataType: "json", success: function(data){ re = new RegExp("#fileName", "g"); for (var i = 0; i < data.length; i++) { var html = $("#hrefTem").html(); html = html.replace(re,data[i]); $("#searchResult").append(html); } } }); }); } //查询方法 function search(){ $("#searchResult").html(""); var text = $("#searchText").val(); $.ajax({ type: "post", url: "page/search", data: {condition:text,type:2},//2表示点击键盘事件 dataType: "json", success: function(data){ if(data!=null){ re = new RegExp("#fileName", "g"); for (var i = 0; i < data.length; i++) { var html = $("#hrefTem").html(); html = html.replace(re,data[i]); $("#searchResult").append(html); } } } }); } //读取配置文件 function readCfg(fileName){ $.ajax({ type: "post", url: "page/readFile", data: {fileName:fileName},//传入文件名 dataType: "json", success: function(data){ if(data!=null){ //模仿导入的方法写。把值显示在页面上 $("#cp").text(data.cp); $("#ct").text(data.ct); $("#pn").text(data.pn); $("#pm").text(data.pm); $("#pv").text(data.pv); $("#cp2").val(data.cp); $("#ct2").val(data.ct); $("#pn2").val(data.pn); $("#pm2").val(data.pm); $("#pv2").val(data.pv); }else{ alert("读取配置文件失败") } } }); } //获取页面值 并封装成json对象 function getFromValue(){ var obj ={ pm :$("#pm").text(), pv : $("#pv").text(), pn :$("#pn").text() } return obj; } </script> <!-- 代码模版用于动态生成 --> <script id="hrefTem" type="text/template"> <a onclick="readCfg(#fileName)">#fileName</a><br> </script> </body> </html>
以上是关于最新版web 配置平台页面的主要内容,如果未能解决你的问题,请参考以下文章