1.怎么使用poi导出word和excel?
1.1动态生成excel
- //创建HSSFWorkbook对象
- HSSFWorkbook wb = new HSSFWorkbook();
- //创建HSSFSheet对象
- HSSFSheet sheet = wb.createSheet("sheet0");
- //创建HSSFRow对象
- HSSFRow row = sheet.createRow(0);
- //创建HSSFCell对象
- HSSFCell cell=row.createCell(0);
- //设置单元格的值
- cell.setCellValue("单元格中的中文");
- //输出Excel文件
- FileOutputStream output=new FileOutputStream("d:\\workbook.xls");
- wkb.write(output);
- output.flush();
1.2导出Excel
- /创建HSSFWorkbook对象(excel的文档对象)
- HSSFWorkbook wb = new HSSFWorkbook();
- //建立新的sheet对象(excel的表单)
- HSSFSheet sheet=wkb.createSheet("成绩表");
- //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
- HSSFRow row1=sheet.createRow(0);
- //创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个
- HSSFCell cell=row1.createCell(0);
- //设置单元格内容
- cell.setCellValue("学员考试成绩一览表");
- //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
- sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
- //在sheet里创建第二行
- HSSFRow row2=sheet.createRow(1);
- //创建单元格并设置单元格内容
- row2.createCell(0).setCellValue("姓名");
- row2.createCell(1).setCellValue("班级");
- row2.createCell(2).setCellValue("笔试成绩");
- row2.createCell(3).setCellValue("机试成绩");
- //在sheet里创建第三行
- HSSFRow row3=sheet.createRow(2);
- row3.createCell(0).setCellValue("李明");
- row3.createCell(1).setCellValue("As178");
- row3.createCell(2).setCellValue(87);
- row3.createCell(3).setCellValue(78);
- //.....省略部分代码
- //输出Excel文件
- OutputStream output=response.getOutputStream();
- response.reset();
- response.setHeader("Content-disposition", "attachment; filename=details.xls");
- response.setContentType("application/msexcel");
- wkb.write(output);
- output.close();
- retrun null;
2.说一说你shiro实现安全登录?
1.在maven里加入shiro需要的jar
<!--shiro start-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
<version>1.2.3</version>
</dependency>
<!-- shiro end-->
在web.xml加上Shiro过滤器配置:
编写shiro的ShiroRealm类:
通过sessionManager来统一集合,并且交付给securityManager来管理;
还有realm,这个其实是用来个人实现用户验证、权限授权功能的一个东西,
它也会被securityManager来管理,等等。总而言之,securityManger是shiro的指挥中心、心脏。
在Spring框架里集成Shiro,加入配置
登录验证控制类实现:
登录和退出时都需要跟设置shiro的session,
登录成功,Session会话过期,需要重新登录,保证系统安全性
shiro的整体架构图:
当用户访问时,访问信息发送到了securtymanage.authenticator解析用户数据,通过realms去查用户是否正确。
securitymanage自己实现了一套session管理机制,不需借助外部任何web容器,使用cacheManager来缓存用户的角色和权限数据。realm就是连接数据库的一个桥梁。
认证过程:
shiro授权过程