- 浏览: 1264792 次
- 性别:
- 来自: 杭州
-
文章分类
- 全部博客 (399)
- 心情故事 (12)
- java (115)
- linux (55)
- 关系型数据库 (35)
- struts,jsf,spring (11)
- jdbc,hibernate,ibatis (11)
- jsp,jstl,c:tag,标签库 (2)
- ejb,webservice (1)
- tomcat,jboss,jetty,weblogic,websphere (15)
- java网络编程 (6)
- java线程 (0)
- js,jquery,json,xml,dom,html.regex (25)
- 设计模式 (6)
- BUG记录 (2)
- ant (2)
- jsp,servlet (4)
- swing (6)
- lucene+nutch (6)
- log4j (2)
- windows doc (2)
- ruby (1)
- ruby on rails (3)
- 操作系统网络 (18)
- apache 错误 (1)
- tomcat (10)
- jboss (9)
- jetty (9)
- weblogic (9)
- websphere (10)
- apache (2)
- AIX的iostat命令查看系统磁盘的使用情况 (1)
- oracle 统计一个表格有多少列 (1)
- Exception in thread "main" java.security.KeyStoreException: Windows-MY not found (1)
- jsp (1)
- jstl (1)
- c:tag (1)
- 标签库 (1)
- struts (1)
- jsf (1)
- spring (2)
- oracle,sqlplus (2)
- sqlplus (2)
- show errors (1)
- proc (1)
- function (1)
- ORA-06544: PL/SQL: internal error (1)
- arguments: [55916] (1)
- [] (7)
- 终端身份实施文档 (1)
- 重装系统之后飞鸽传书只能看到自己 (1)
- vsftp "上传 553 Could not create file" (1)
- startWebLogic.sh启动失败,提示Error initializing Embedded LDAP Server (1)
- java agent 注册为 windows 服务 (1)
- centos (1)
- svn (1)
- apr (1)
- apr-util (1)
- activemq (2)
- oracle (5)
- mysql (3)
- nosql (3)
- NSIS (1)
- windows wmic (1)
- c 指针 (1)
- c c++ (0)
- jmeter (0)
- 性能测试 (0)
- linux,备份 (2)
- C++ ,Virtual (1)
- windows dos (1)
- android (2)
- 大数据,云计算 (1)
- JVM垃圾收集 (1)
- jdbc (2)
- invoke (1)
- hibernate (1)
- ibatis (1)
- 个人开源项目源码收藏 (1)
- 批处理 (1)
- Mongodb mapreduce (8)
- kettle (1)
- Mongodb capped (1)
- mongodb gridfs (1)
- Mongodb 入门基础知识 (1)
- mongodb (8)
- hadoop2.5.1 (1)
- hadoop (4)
- eclipse (1)
- hdfs fs (1)
- elipse hadoop plugin (1)
- PHP相关知识 (1)
- js (1)
- jquery (1)
- json (1)
- xml (1)
- dom (1)
- html.regex (1)
- 网络知识 (1)
- nginx (1)
- docker (1)
- 测试 (1)
- nodejs (1)
- iptables (1)
- linux gitlab (1)
最新评论
-
July01:
最近了解到一款StratoIO打印控件,功能如下:1、Html ...
web页面调用window.print()函数实现打印的功能 -
hxdtech:
非常感谢!
我在学习ibatis时的培训ppt -
zmwxiaoming:
what 能连数据库不错
SOLR的学习整理 -
springdata_springmvc:
java程序语言学习教程 地址http://www.zuida ...
java获取当前操作系统的信息 -
huanzei:
整理的不错,
oracle lpad函数
spring内置了定时器,其实是对java.util.timer的一个自己的实现。通过它可以定时的做一些任务,比如定时的发送邮件,同样的,spring对javaMail也进行了一些封装。看配置文件。
这个是配置文件mail.property
mail.username=xxxx mail.password=xxxx mail.host=mail.mchz.com.cn mail.from=xxxx@mchz.com.cn mail.smtp.auth=true mail.debug=true resource=/xls ipaddress=172.16.4.110
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <import resource="applicationContext-propertyConfigurer.xml"/> <!-- 定时调度 --> <bean id="LoginAuditService" class="com.hzmc.capaa.business.search.impl.LoginAuditSendMailService"> <property name="from" value="${mail.from}"/> <property name="resource" value="${resource}"/> <property name="ipaddress" value="${ipaddress}"/> </bean> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="LoginAuditService"/> <property name="targetMethod" value="sendLoginAuditMailReport"/> </bean> <bean id="jobTiger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="jobDetail"/> <property name="cronExpression" value="0 45 8 * * ?"/> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="jobTiger"/> </list> </property> <property name="autoStartup" value="true"/> </bean> <!-- 邮件配置 --> <bean id="sender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="${mail.host}"/> <property name="username" value="${mail.username}"/> <property name="password" value="${mail.password}"/> <property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">${mail.smtp.auth}</prop> <prop key="debug">${mail.debug}</prop> </props> </property> </bean> </beans>
下面是业务类,负责发邮件的业务类。代码包含用jexcelAPI生成excel文件
package com.hzmc.capaa.business.search.impl; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import jxl.Workbook; import jxl.format.UnderlineStyle; import jxl.write.WritableFont; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import com.hzmc.capaa.business.auditselect.AuditSelectManager; import com.hzmc.capaa.business.search.LoginAuditSearchManager; import com.hzmc.capaa.business.userconfig.UserConfigFileManager; import com.hzmc.capaa.domain.persistence.audit.AuditSelect; import com.hzmc.capaa.domain.persistence.search.LoginAuditSearch; import com.hzmc.capaa.domain.persistence.userconfig.UserConfigFile; import com.hzmc.capaa.web.util.GetCurrentDateTime; public class LoginAuditSendMailService { @Autowired private JavaMailSender sender; @Autowired private UserConfigFileManager userConfigFileManger; @Autowired private LoginAuditSearchManager loginAuditSearchManager; @Autowired private AuditSelectManager auditSelectManager; private String from; private String ipaddress; private Resource resource; public void setFrom(String from) { this.from = from; } public void sendLoginAuditMailReport() { getCapaaUserList(); } @SuppressWarnings("unchecked") public void getCapaaUserList() { List<UserConfigFile> userList = this.userConfigFileManger .getUserConfigFileList(); for (UserConfigFile user : userList) { String name = user.getCapaaUser(); String moudle = user.getAuditModule(); String tomail = user.getUserEmail(); String title = "您的关于登录审计的定制信息"; String content = "你订阅的审计信息已经收到,请点击下面的链接下载或查看!\n"; String[] moudles = moudle.split(";"); for (String model : moudles) { if (model.indexOf("a") != -1) { //标示关注登录审计模块 LoginAuditSearch loginAudit = this.loginAuditSearchManager .checkIsExists(name); if (loginAudit == null) { // 直接默认处理 getLoginAuditDataList(name,"1=1",tomail,title,content); } else { // 加上默认的审计条件 String dbUser=loginAudit.getDbUser(); BigDecimal dbId=loginAudit.getDbId(); String osUser=loginAudit.getOsUser(); String realUser=loginAudit.getRealUser(); String ipAddress=loginAudit.getIpAddress(); String appName=loginAudit.getApplication(); String timeStamp=loginAudit.getTimestamp(); String whereFilter = "1=1"; if (dbUser != null && !"".equals(dbUser)) { whereFilter += " and dbuser ='" + dbUser + "'"; } if (dbId != null && !"".equals(dbId)) { whereFilter += " and dbid='" + dbId + "'"; } if (osUser != null && !"".equals(osUser)) { whereFilter += " and osuser like '%" + osUser + "%'"; } if (realUser != null && !"".equals(realUser)) { whereFilter += " and realuser like '%" + realUser + "%'"; } if (ipAddress != null && !"".equals(ipAddress)) { whereFilter += " and IP_ADDRESS like '%" + ipAddress + "%'"; } if (appName != null && !"".equals(appName)) { whereFilter += " and APP_NAME like '%" + appName + "%'"; } if (timeStamp != null && !"".equals(timeStamp)) { whereFilter += " and TIMESTAMP >= to_date('" + timeStamp + "','yyyy-mm-dd HH24:mi')"; } getLoginAuditDataList(name,whereFilter,tomail,title,content); } } } } } @SuppressWarnings("unchecked") private void getLoginAuditDataList(String name,String whereFilter,String tomail,String title,String content) { Map map = new HashMap(); map.put("ipAddress", whereFilter); map.put("dbId", new BigDecimal(0)); map.put("countNumber", new Integer(200)); map.put("clientId", UUID.randomUUID().toString()); List<AuditSelect> list = this.auditSelectManager .getAuditSelectByPages(map); String fileName = name + GetCurrentDateTime.getCurrentTime()+".xls"; if (list != null) { try { if(!resource.getFile().getAbsoluteFile().exists()){ File f=new File(resource.getFile().getAbsolutePath()); f.mkdir(); } extExcel(list, resource.getFile().getAbsolutePath()+"\\"+fileName); } catch (IOException e) { e.printStackTrace(); } } content="http://"+ipaddress+":8082/capaa/xls/"+fileName; sendMailtoCapaaUser(tomail,title,content); } @SuppressWarnings("unchecked") public void extExcel(List<AuditSelect> loginList, String fileName) { File file = new File(fileName); jxl.write.WritableWorkbook wwb = null; jxl.write.WritableSheet ws = null; try { file.createNewFile(); wwb = Workbook.createWorkbook(file); ws = wwb.createSheet("LoginAuditSheet", 0); jxl.write.Label labela = new jxl.write.Label(0, 0, "数据库用户"); jxl.write.Label labelb = new jxl.write.Label(1, 0, "IP地址"); jxl.write.Label labelc = new jxl.write.Label(2, 0, "应用程序"); jxl.write.Label labeld = new jxl.write.Label(3, 0, "登录时间"); jxl.write.Label labele = new jxl.write.Label(4, 0, "响应行为"); jxl.write.Label labelf = new jxl.write.Label(5, 0, "审计级别"); jxl.write.Label labelg = new jxl.write.Label(6, 0, "错误性息"); ws.addCell(labela); ws.addCell(labelb); ws.addCell(labelc); ws.addCell(labeld); ws.addCell(labele); ws.addCell(labelf); ws.addCell(labelg); for(int i=1;i<loginList.size()+1;i++){ AuditSelect loginAudit=(AuditSelect)loginList.get(i-1); String dbUser = loginAudit.getDbUser(); String ipAddress = loginAudit.getIpAddress(); String appLication = loginAudit.getAppName(); String loginTime = loginAudit.getTimestamp().toString(); String reaction = loginAudit.getAuditClass(); String auditLevel = loginAudit.getAuditLevel().toString(); String errInfo = loginAudit.getErrMsg(); jxl.write.Label lable1 = new jxl.write.Label(0, i, dbUser); jxl.write.Label lable2 = new jxl.write.Label(1, i, ipAddress); jxl.write.Label lable3 = new jxl.write.Label(2, i, appLication); jxl.write.Label lable4 = new jxl.write.Label(3, i, loginTime); jxl.write.Label lable5 = new jxl.write.Label(4, i, reaction); jxl.write.Label lable6 = new jxl.write.Label(5, i, auditLevel); jxl.write.Label lable7 = new jxl.write.Label(6, i, errInfo); ws.addCell(lable1); ws.addCell(lable2); ws.addCell(lable3); ws.addCell(lable4); ws.addCell(lable5); ws.addCell(lable6); ws.addCell(lable7); } jxl.write.WritableFont wfc = new jxl.write.WritableFont( WritableFont.ARIAL, 20, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN); jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat( wfc); wcfFC.setBackground(jxl.format.Colour.RED); wwb.write(); wwb.close(); } catch (Exception ex) { ex.printStackTrace(); } } private void sendMailtoCapaaUser(String tomail, String title, String content) { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(from); message.setTo(tomail); message.setSubject(title); message.setText(content); sender.send(message); } public void setResource(Resource resource) { this.resource = resource; } public void setIpaddress(String ipaddress) { this.ipaddress = ipaddress; } } //假如是发送html邮件,那么用MimeMessage MimeMessage msg = sender.createMimeMessage(); try { MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8"); helper.setFrom(from); helper.setTo(tomail); helper.setSubject(title); helper.setText(content,true); sender.send(msg); } catch (MessagingException e) { e.printStackTrace(); }
发表评论
-
一个JSF的入门例子
2009-11-09 14:00 1791public class UserBean { pr ... -
SpringORM (ibatis)的一个例子
2009-07-24 11:23 1767@Service @Transactional publi ... -
Spring DAO的一个小例子
2009-07-24 11:20 1613采用SpringDAO自身的数据库处理类。 import j ... -
jdk和cglib动态代理的demo
2009-07-09 17:12 1756JDK的动态代理是基于接口的 package ... -
Spring IOC简单实例
2009-07-09 15:30 2097把对类的实例化工作从类内部转交给Spring的IOC容器来做 ... -
spring2.5文件上传 fileUpload
2009-06-10 14:14 2482spring的文件上传 1jar包:commons-fil ... -
spring2.5学习笔记之三:spring对JDBC的支持
2009-04-17 12:59 1661在DAO类中,我们继承Spring的DAO,代码如下: j ... -
spring学习笔记之二:Spring对事务的支持
2009-04-17 12:06 12241spring对事务的管理提供了一致的编程模板,在高层 ... -
spring2.5学习笔记之一:IOC和MVC
2009-04-16 16:29 22881spring2.5的使用在配置上已经有了很大的 ... -
IOC 容器实例化的5钟方法
2008-12-10 11:13 1393方法一: Applicati=onCon ...
相关推荐
- **权限管理**:整合Shiro和Spring Security,实现用户权限管理。 - **搜索引擎**:整合ElasticSearch,实现高性能搜索引擎。 - **分布式服务**:整合Dubbo框架,实现RPC服务远程调用。 - **文件系统管理**:整合...
1. **JavaMail API**:用于创建和发送电子邮件,处理SMTP协议。 2. **第三方邮件库**:如Apache Commons Email,提供更高级的功能,如HTML邮件、附件等。 3. **Spring框架**:提供方便的定时任务管理,如`@Scheduled...
对于Spring用户,可以利用Spring的`@Scheduled`注解和`TaskScheduler`接口来实现定时任务。`@Scheduled`注解可以直接放在方法上,声明任务的执行周期,而`TaskScheduler`则提供了更高级的定制选项。例如: ```java...
6. **MVC(Model-View-Controller)模式**:JSP通常应用于视图层,配合Servlet或Spring MVC等框架实现模型和控制器,构建三层架构的Web应用。 7. **JSP七大项目**: - 可能包括登录注册系统,展示用户管理功能,这...
为了保证系统的可扩展性和灵活性,设计上可能采用了面向接口编程和依赖注入(DI)原则,Spring框架是一个常用的实现方式。通过Spring,我们可以方便地管理bean,实现AOP(面向切面编程)来处理日志、事务管理等跨切...
这通常通过Java的定时器(java.util.Timer)或者更高级的Quartz Scheduler来完成,允许用户设定周期性地生成报告。系统可能还包含了事件驱动和观察者模式,以便在报告生成后自动通知相关人员。 对于报告的共享,...
Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中。它提供了巨大的灵 活性而不牺牲简单性。你能够用它来为执行一个作业而创建简单的或复杂的调度。它有很多特征,如:数据库支持,...