在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段<Context path=”Welcome” docBase=”c:\hello\hello” reloadable=”true” />,该代码片段中每个属性的含义与用途是什么?
contex指上下文,实际上就是一个web项目; path是虚拟目录,访问的时候用127.0.0.1:8080/welcom/*.jsp访问网页,welcome前面要加/; docBase是网页实际存放位置的根目录,映射为path虚拟目录; reloadable="true"表示你修改了jsp文件后不需要重启就可以实现显示的同步。
/** * http://localhost:8080/CQMarketSupervise/exportEntity.do?fCheckType=&fStatus= */ @RequestMapping(value = "exportEntity", produces = { "application/json;charset=UTF-8" }) @ResponseBody public ReturnData exportEntity(@RequestParam String fCheckType, @RequestParam String fStatus,HttpServletRequest request) { ReturnData redata = new ReturnData(); //服务器保存路径 String path1 = request.getSession().getServletContext().getRealPath(""); //服务ip地址和端口 String ip="http://"+request.getLocalAddr()+":"+request.getLocalPort(); try { Map<String, Object> params = new HashMap<String, Object>(); if (fCheckType != null && !fCheckType.isEmpty()) { params.put("fCheckType", fCheckType ); } if (fStatus != null && !fStatus.isEmpty()) { params.put("fStatus", fStatus); } String path=checkTaskservice.exportEntity(params,path1,ip); redata.setData(path); } catch (Exception e) { e.printStackTrace(); return null; } return redata; }
/** * http://localhost:8080/CQMarketSupervise/exportEntity.do?fCheckType=&fStatus= */ @RequestMapping(value = "exportEntity", produces = { "application/json;charset=UTF-8" }) @ResponseBody public ReturnData exportEntity(@RequestParam String fCheckType, @RequestParam String fStatus,HttpServletRequest request) { ReturnData redata = new ReturnData(); //服务器保存路径 String path1 = request.getSession().getServletContext().getRealPath(""); //服务ip地址和端口 String ip="http://"+request.getLocalAddr()+":"+request.getLocalPort(); try { Map<String, Object> params = new HashMap<String, Object>(); if (fCheckType != null && !fCheckType.isEmpty()) { params.put("fCheckType", fCheckType ); } if (fStatus != null && !fStatus.isEmpty()) { params.put("fStatus", fStatus); } String path=checkTaskservice.exportEntity(params,path1,ip); redata.setData(path); } catch (Exception e) { e.printStackTrace(); return null; } return redata; }
@Override public String exportEntity(Map<String, Object> params,String path,String ip) { ExcelUtil excelUtil=new ExcelUtil(); System.out.println("list:"+checkTaskMapper.exportEntity(params).size()); return excelUtil.exportExcel(checkTaskMapper.exportEntity(params),path,ip); }
/** * 写入数据到excel */ public String exportExcel(List<Map<String,Object>> list,String path,String ip){ try{ WritableWorkbook wwb = null; // 创建可写入的Excel工作簿 //String filePath = FileData.class.getResource("").getPath(); //String filePath = "/CQMarketSupervise/WEB-INF/classes/com/CQMarketSupervise/data/"; SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd"); Random random=new Random(); String fileN="CheckTask_"+random.nextInt(1000)+"_"+dateFormat.format(new Date())+".xls"; String fileName1="\\"+fileN; String fileName="D:\\oracle_c\\DATE"+fileName1; File file=new File(fileName); if (!file.exists()) { file.createNewFile(); } //以fileName为文件名来创建一个Workbook wwb = Workbook.createWorkbook(file); // 创建工作表 WritableSheet ws = wwb.createSheet("Test Shee 1", 0); //要插入到的Excel表格的行号,默认从0开始 Label fEntityName= new Label(0, 0, "主体名称");//表示第 Label fBizlicNum= new Label(1, 0, "注册号"); Label fAddress= new Label(2, 0, "地址"); Label fFilishUser= new Label(3, 0, "核查人"); Label fFilishDate= new Label(4, 0, "核查时间"); Label fResult= new Label(5, 0, "核查结果"); ws.addCell(fEntityName); ws.addCell(fBizlicNum); ws.addCell(fAddress); ws.addCell(fFilishUser); ws.addCell(fFilishDate); ws.addCell(fResult); for (int i = 0; i < list.size(); i++) { Label fEntityName_i= new Label(0, i+1, list.get(i).get("fEntityName")+""); Label fBizlicNum_i= new Label(1, i+1, list.get(i).get("fBizlicNum")+""); Label fAddress_i= new Label(2, i+1, list.get(i).get("fAddress")+""); Label fFilishUser_i= new Label(3, i+1, list.get(i).get("fFilishUser")+""); Label fFilishDate_i= new Label(4, i+1, list.get(i).get("fFilishDate")+""); Label fResult_i= new Label(5, i+1, list.get(i).get("fResult")+""); ws.addCell(fEntityName_i); ws.addCell(fBizlicNum_i); ws.addCell(fAddress_i); ws.addCell(fFilishUser_i); ws.addCell(fFilishDate_i); ws.addCell(fResult_i); } //写进文档 wwb.write(); // 关闭Excel工作簿对象 wwb.close(); return ip+"/GSfile/"+fileN; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
<Context docBase="D:\oracle_c\DATE" path="/GSfile" reloadable="true"/><Context docBase="CQMarketSupervise" path="/CQMarketSupervise" reloadable="true" source="org.eclipse.jst.jee.server:CQMarketSupervise"/></Host>