常用技术

Activiti工作流

Activiti5框架说明:     

      Activiti5工作流引擎框架: 它实际上是一个javaEE的半成品项目(企业一般用它来做二次开发).

      -- dao层.

      -- service层.

      -- 它有数据库表(24表). Activiti5.18 (2015.7.31)

      -- Activiti5底层用得持久层框架是MyBatis3,

          它有自己的数据库表,提供了七个核心业务服务类.

Activiti5工作流引擎下载与安装:

-- 它的官方网站:http://www.activiti.org

    -- 下载: activiti-5.18.0.zip(2015.7.31)

    -- 解压:

         database : (数据库相关)存放了Activiti框架的sql语句.

          docs: api文档、用户指南、xsd

          libs: 存放了自己所有的jar.

          wars: web应用.

-- 离线安装:

              装备好activiti-designer插件安装包拷贝到eclipse安装目录dropins下.

              eclipse\dropins\activiti-plugin

安装数据库表:

 第一种方式:(通过sql语句)

           -- mysql(版本5.5以下)activiti-5.18.0\database\create\:

              -- activiti.mysql.create.engine.sql

              -- activiti.mysql.create.history.sql

              -- activiti.mysql.create.identity.sql

 

           -- mysql(版本5.5或以上)

              -- activiti.mysql55.create.engine.sql

              -- activiti.mysql55.create.history.sql

              -- activiti.mysql.create.identity.sql

第二种方式:编程方式(硬编码方式)

-- 拷贝jar(required文件夹中所有的jar).

           -- 编程步骤:

              第一步:创建流程引擎配置信息对象(ProcessEngineConfiguration).

              /** 创建流程引擎配置信息对象 */

                   ProcessEngineConfiguration pec = ProcessEngineConfiguration

                                     .createStandaloneProcessEngineConfiguration();

                  

                   /**############# 为流程引擎配置信息对象设置信息  ##############*/

                   /** 设置数据库的类型 */

                   pec.setDatabaseType("mysql");

                   /**

                    * 设置创建数据库表的方式

                    * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE (true): 如果没有数据库表就会创建数据库表,有的话会修改表结构

                    * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE (false): 不会创建数据库表.

                    * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP (create-drop): 先创建数据库表,再删除表

                    * */

                   pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

                   /** 设置数据库驱动 */

                   pec.setJdbcDriver("com.mysql.jdbc.Driver");

                   /** 设置连接数据库URL */

                   pec.setJdbcUrl("jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf-8");

                   /** 设置连接数据库用户名 */

                   pec.setJdbcUsername("root");

                   /** 设置连接数据库密码 */

                   pec.setJdbcPassword("root");

                  

             第二步:创建流程引擎(ProcessEngine).

             ProcessEngine pe = pec.buildProcessEngine();

Activity工作流表说明(重点)

-- activiti5.18 : 24表.

表的设计:项目名_模块名_持久化类名(hibernate|jpa).

a. act_ge_*(activiti_general_*): 2张表.

       -- 全局通用数据.

       对应获取:RepositoryService仓储服务

 

b. act_hi_*(activiti_history_*): 8张表.

-- 'HI' 历史的数据: 过期流程实例, 过期流程变量, 过期任务等.

       对应获取: HistoryService 历史服务

     

c. act_id_*(activiti_identity_*): 4张表.

-- 'ID' 权限管理数据:用户、组等.

        对应获取: IdentityService权限服务

 

    d. act_re_*(activiti_repository_*): 3张表.

       -- 'RE' 仓储数据: 流程定义、流程资源信息 (如图片资源、规则等).

       对应获取:RepositoryService仓储服务.

 

e. act_ru_*(activiti_runtime_*): 6张表.

-- 'RU' 运行过程中的流程数据:流程实例、用户任务、流程变量、调度任务等.

       对应获取:RuntimeService运行服务

     

f. act_evt_log(activiti_event_logging) : 1张表.

核心api说明:

ProcessEngineConfiguration.流程引擎配置信息类.

     属性的设置、构建流程引擎.

ProcessEngine: 流程引擎.

     获取七个业务处理类.

1. RepositoryService仓储服务:

         对应表:act_re_*、act_ge_*

 

    2. RuntimeService运行时服务

         对应表:act_ru_*

 

    3. TaskService任务服务

              对应表:act_ru_*

 

    4. FormService表单服务

 

    5. IdentityService身份服务

         对应表:act_id_*

 

    6. HistoryService历史服务

         对应表:act_hi_*

 

    7. ManagementService管理服务.

         对应表:act_id_*、act_evt_log

主要方法查询APi

Maven

Maven简介

  • 下载网址

–      http://maven.apache.org/download.cgi

–      下载版本 3.2.3 (最新:3.3.9)

l  Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具

l  Maven是一个项目管理工具,它包含:

l  一个项目对象模型 (Project Object Model)

l  一组标准集合

l  一个项目生命周期(Project Lifecycle)

   清理、编译、测试、报告、打包、部署

l  一个依赖管理系统(Dependency Management System)

使用前提:

当通过配置文件确定依赖关系之后,maven将自动从指定的位置(互联网)下载需要项目(jar包)。第一次使用maven,需要联网。

思想:

约定优于配置的思想

 

 

Maven提供相应的插件完成以上流程,上面对应的每个都是插件。

Maven安装

配置 MAVEN_HOME = maven压缩包解压目录(必须放在JAVA_HOME后面)

 

 

在path环境变量中 增加 %MAVEN_HOME%\bin

 

 

在cmd窗口测试  mvn –v 显示如下就成功

 

 

配置本地仓库

打开maven解压目录进入conf文件夹F:\apache-maven-3.2.3\conf

打开setting.xml配置文件修改(输入需要存放的本地仓库)

 

 

setting.xml中可以设置的属性

l  <localRepository> 配置本地仓库的目录

l  <interactiveMode>是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true

l  <offline> 是否需要在离线模式下运行

l  <pluginGroups> 插件组。默认情况下该列表包含了org.apache.maven.plugins

l  <proxies>通过代理访问外部库

l  <servers> 配置服务端的设置。例如:安全认证

l  <mirrors> 镜像库。确定使用的仓库

l  <profiles> 根据环境参数来调整构建配置的列表。为pom.xml的profile简化版。需要激活才可生效

l  <activeProfiles>手动激活profiles的列表

   注意:必须与<profile><id>名称一致

Maven常用指令:

在eclipse中可以省略mvn不写

在cmd下使用命令,必须在项目的根下进行的,及可以看到pom.xml

l  编译

n  mvn compile

l  测试

n  mvn test  //运行测试、mvn test -Dtest=${类名} //单独运行测试类

l  清除

n  mvn clean  //将清除原来编译的结果

l  打包

n  mvn package、mvn package –Dmaven.test.skip=true //打包时不执行测试

l  安装发布

n  mvn install //将项目打包成构件安装到本地仓库

n  mvn deploy  //发布到本地仓库或服务器(例如Tomcat、Jboss)

其它命令:

转换Eclipse工程 (在pom.xml目录执行)

 mvn eclipse:eclipse

 mvn eclipse:clean  //清除Eclipse设置信息

转换成IDEA 工程(在pom.xml目录执行)

mvn idea:idea

mvn idea:clean //清除idea设置信息

显示一个插件的详细信息(configuration, goals等):

mvn help:describe -Dplugin=pluginName -Ddetail

注意点:

1:第一次使用指令需要联网下载插件

2:想部署到服务器上,必须先运行命令mvn install安装到本地仓库

Maven声明周期

  •     validate
  •     generate-sources
  •     process-sources
  •     generate-resources
  •     process-resources     复制并处理资源文件,至目标目录,准备打包。
  •     compile     编译项目的源代码。
  •     process-classes
  •     generate-test-sources
  •     process-test-sources
  •     generate-test-resources
  •     process-test-resources     复制并处理资源文件,至目标测试目录。
  •     test-compile     编译测试源代码。
  •     process-test-classes
  •     test     使用合适的单元测试框架运行测试。这些测试代码不会被打包或部署。
  •     prepare-package
  •     package     接受编译好的代码,打包成可发布的格式,如 JAR 。
  •     pre-integration-test
  •     integration-test
  •     post-integration-test
  •     verify
  •     install     将包安装至本地仓库,以让其它项目依赖。
  •     deploy     将最终的包复制到远程的仓库,以让其它开发人员与项目共享。

生命周期从上往下执行,到执行到指定生命周期时,前面自动完成。

pom.xml文件解析(重点)

coordinates-坐标

在仓库中唯一标识项目位置三个参数

<groupId> 组

<artifactId> 标识

<version>  版本号

如下:

<groupId>cn.itcast.parent</groupId>

  <artifactId>parent</artifactId>

  <version>0.0.1-SNAPSHOT</version>

示例:仓库\cn\itcast\maven\demojava\0.0.1-SNAPSHOT

dependencies-依赖

依赖具有传递性

 

 

一个项目依赖在编译或运行等阶段另一个项目

1:可以右键maven-add dependency输入需要的jar包复制坐标进行添加

2:可以进入http://www.mvnrepository.com/artifact/org.springframework/spring-core网站查找坐标

<dependencies>

         <dependency>

         <groupId>junit</groupId>

         <artifactId>junit</artifactId>

         <version>${junit.version}</version>

         <scope>test</scope>

         </dependency>

         <!-- 6 json lib -->

         <dependency>

            <groupId>net.sf.json-lib</groupId>

            <artifactId>json-lib</artifactId>

            <version>${json-lib.version}</version>

            <classifier>jdk15</classifier>

         </dependency>

      </dependencies>

scope-依赖范围

compile:编译范围,默认scope,在classpath中存在

provided:已提供范围,比如容器提供Servlet API

runtime:运行时范围,编译不需要,接口与实现分离

test:测试范围,单元测试环境需要

system:系统范围,自定义构件,指定systemPath

 

 

依赖冲突:

如果直接与间接依赖中包含有同一个坐标不同版本的资源依赖,以直接依赖的版本为准(就近原则)

如果直接依赖中包含有同一个坐标不同版本的资源依赖,以配置顺序下方的版本为准(就近原则)

 

 

依赖排除:

点击eclipse下方窗口Declaration

 

 

 

Aggregation-聚合

将项目分解为多个不同模块,快速构建项目

 

 

运行结果:

 

 

inheritance-继承

 

 

都具有这个属性:

<parent>

  <groupId>cn.itcast.parent</groupId>

   <artifactId>parent</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  </parent>

模块:将一个项目拆分成多个子项目。

继承:子项目与父项目之间关系。

 

项目之间继承,实现POM复用,依赖管理,锁定版本号

父类maven项目:

<dependencyManagement>

      <dependencies>

         <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-context</artifactId>

            <version>${spring.version}</version>

         </dependency>

      </dependencies>

   </dependencyManagement>

子类maven项目(继承了父类):写下父类的坐标

<parent>

  <groupId>cn.itcast.parent</groupId>

   <artifactId>parent</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  </parent>

然后在依赖中可以不指定与父类同jar包的版本

<dependencies>

      <!-- 1.1 spring context -->

      <dependency>

         <groupId>org.springframework</groupId>

         <artifactId>spring-context</artifactId>

      </dependency>

</dependencies>

Pom.xml核心配置

  • pom.xml是Maven项目的核心配置文件,位于每个工程的根目录,指示Maven工作的元数据文件
  • <project > :文件的根节点 .
    <modelversion > : pom.xml使用的对象模型版本 .
    <groupId > :创建项目的组织或团体的唯一 Id.
    <artifactId > :项目的唯一 Id, 可视为项目名 .
    <version > :产品的版本号 .

         <packaging > :打包类型,一般有jar、war、pom 等
<name > :项目的显示名,常用于 Maven 生成的文档。 
<description > :项目描述,常用于 Maven 生成的文档

常见maven错误

启动服务器报错

Artifact Project3:war exploded: Error during artifact deployment. See server log for details

依赖了多个maven jar包冲突

需要在依赖中排除:

典型:极光推送

<dependency>
   <groupId>cn.jpush.api</groupId>
   <artifactId>jpush-client</artifactId>
   <version>3.2.11</version>
   <exclusions>
      <exclusion>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-release-plugin</artifactId>
      </exclusion>
   </exclusions>
</dependency>

Maven打包方式

<build>
   <finalName>bg-platform-web</finalName>
       <outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
   <plugins>
      <!-- 打包插件 -->
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.5</version>
      </plugin>
      <!-- 编译插件 -->
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.2</version>
         <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
         </configuration>
      </plugin>

      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>2.9</version>
         <executions>
            <execution>
               <id>copy</id>
               <phase>package</phase>
               <goals>
                  <goal>copy-dependencies</goal>
               </goals>
               <configuration>
                  <outputDirectory>${project.build.directory}/lib</outputDirectory>
               </configuration>
            </execution>
         </executions>
      </plugin>

      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
            <execution>
               <id>pushPackage</id>
               <phase>run</phase>

               <configuration>
                  <target name="push service">
                     <!--<echo message="${basedir}" />-->

                     <copy todir="${project.build.directory}/classes">
                        <fileset dir="${basedir}/src/main/webapp/WEB-INF/classes">
                           <include name="**/*" />
                        </fileset>
                     </copy>

                     <!-- 打整个程序运行包 -->
                     <copy todir="${project.build.directory}/release/config">
                     <fileset dir="${project.build.directory}/classes">
                        <include name="*.*"/>
                        <include name="mappers/*.xml"/>
                     </fileset>
                      </copy>
                     <copy todir="${project.build.directory}/release/lib">
                        <fileset dir="${project.build.directory}/lib" />
                     </copy>

                     <pathconvert pathsep=" " property="mf.classpath">
                        <chainedmapper>
                           <flattenmapper />
                           <globmapper from="*" to="lib/*" />
                        </chainedmapper>
                        <path id="classpath">
                           <fileset dir="${project.build.directory}/release/lib">
                              <include name="**/*" />
                           </fileset>
                        </path>
                     </pathconvert>
                     <!--打包推送服务-->
                     <jar
                           destfile="${project.build.directory}/release/bagtree-push-${project.version}.jar"
                           basedir="${project.build.directory}/classes">
                        <include name="com/bagtree/common/**"/>
                        <include name="com/bagtree/push/**"/>
                        <include name="com/bagtree/sms/**"/>
                        <include name="com/bagtree/mapper/**"/>
                        <include name="com/bagtree/model/**"/>
                        <include name="com/bagtree/service/**"/>
                        <include name="com/bagtree/vo/**"/>


                        <manifest>
                           <attribute name="Built-By" value="${user.name}" />
                           <attribute name="Main-Class"
                                    value="com.bagtree.push.Main" />
                           <attribute name="Class-Path" value="config/ . ${mf.classpath}" />
                        </manifest>
                        <metainf dir="${project.build.directory}/classes">
                           <include name="spring/*" />
                           <include name="mappers/*" />
                        </metainf>
                     </jar>
                     <!--启动sms线程-->
                     <jar
                           destfile="${project.build.directory}/release/bagtree-start-${project.version}.jar"
                           basedir="${project.build.directory}/classes">
                        <include name="com/bagtree/common/**"/>
                        <include name="com/bagtree/send/**"/>
                        <include name="com/bagtree/sms/**"/>
                        <include name="com/bagtree/mapper/**"/>
                        <include name="com/bagtree/model/**"/>
                        <include name="com/bagtree/service/**"/>
                        <include name="com/bagtree/vo/**"/>


                        <manifest>
                           <attribute name="Built-By" value="${user.name}" />
                           <attribute name="Main-Class"
                                    value="com.bagtree.send.Main" />
                           <attribute name="Class-Path" value="config/ . ${mf.classpath}" />
                        </manifest>
                        <metainf dir="${project.build.directory}/classes">
                           <include name="spring/*" />
                           <include name="mappers/*" />
                        </metainf>
                     </jar>
                  </target>
               </configuration>
               <goals>
                  <goal>run</goal>
               </goals>
            </execution>
         </executions>
      </plugin>

      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-resources-plugin</artifactId>
         <version>2.7</version>
         <configuration>
            <encoding>UTF-8</encoding>
         </configuration>
      </plugin>

      <!-- 单元测试插件 -->
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.18.1</version>
         <configuration>
            <argLine>-Dfile.encoding=UTF-8</argLine>
            <skipTests>true</skipTests>
         </configuration>
      </plugin>

      <!-- 源码插件 发布时自动将源码同时发布的配置 -->
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-source-plugin</artifactId>
         <version>2.4</version>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>jar-no-fork</goal>
               </goals>
            </execution>
         </executions>
      </plugin>

      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.8</version>
      </plugin>
     
      <plugin>
         <groupId>org.eclipse.jetty</groupId>
         <artifactId>jetty-maven-plugin</artifactId>
               <version>9.3.8.v20160314</version>
         <configuration>
            <webApp>
               <contextPath>/</contextPath>
               <defaultsDescriptor>${basedir}/src/main/webapp/WEB-INF/lib/webdefault.xml</defaultsDescriptor>
            </webApp>
            <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
            <stopKey>stop</stopKey>
            <stopPort>8089</stopPort>
         </configuration>
      </plugin>

      <plugin>
         <groupId>com.evergrande.mybatis.generator</groupId>
         <artifactId>mybatis-generator-maven-plugin</artifactId>
         <version>1.3.2.1-SNAPSHOT</version>
         <configuration>
            <configurationFile>${basedir}/src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
            <verbose>true</verbose>
            <overwrite>true</overwrite>
         </configuration>
         <executions>
            <!-- mvn mybatis-generator:generate -e -->
            <execution>
               <id>Generate MyBatis Artifacts</id>
               <phase>generate</phase>
               <goals>
                  <goal>generate</goal>
               </goals>
            </execution>
         </executions>
         <dependencies>
            <dependency>
               <groupId>mysql</groupId>
               <artifactId>mysql-connector-java</artifactId>
               <version>${mysqlcj.version}</version>
            </dependency>
         </dependencies>
      </plugin>

   </plugins>
</build>
   <packaging>war</packaging>

 

Redis缓存

Redis使用命令查询地址http://redis.readthedocs.io/en/2.4/index.html

Redis常用的命令

判断是否存在key: exists

Boolean exists = jedis.exists(serializeKey(key));

模糊查询keys(需要模糊查询的值打*号)

jedis.keys("SE_push_*_"+key);

map集合类型存放hset

jedis.hset(serializeKey(key),serializeValue(ltUser),serializeValue(ltPass));

map集合类型取值:hget

byte[] value = jedis.hget(serializeKey(key), field.getBytes());

Redis特殊用处场景

Redis队列

入队列:lpush

jedis.lpush(serializeKey(key), serializeValue(value));

出队列:brpop

List<byte[]> list = jedis.brpop(0,serializeKey(key));

两个出队列:

List<byte[]> list = jedis.brpop(0,serializeKey(key),serializeKey(key2));

Redis排名

添加有序元素:zadd (value为数值)

jedis.zadd(serializeKey(key),value,serializeValue(name));

返回指定key值有序排名:zrank

Long zrank = jedis.zrank(serializeKey(key), serializeValue(name));

返回指定集合的基数:zcard

Long zrank = jedis.zcard(serializeKey(key));

算出排名

System.out.println("超越了百分之几 "+(float) (名次)/(基数)*100);

IOS原生推送

Maven依赖:

<notnoop.version>1.0.0.Beta6</notnoop.version>

<dependency>
   <groupId>com.notnoop.apns</groupId>
   <artifactId>apns</artifactId>
   <version>${notnoop.version}</version>
</dependency>

Ios原生推送主要配置:

1:APNS推送需要的证书

2:APNS证书密码

3:指定设备的token例如:4719f6c7 bb1839d7 d543fcd2 d1edba47 a283ea0f d73e9aba d40cb43b dcbe7129 长度固定

ApnsService service = APNS.newService().withCert(p12Path, IosPushPassWord).asPool(IosCapacity).withAppleDestination(IosProduction).build();

withCert() 需要开发者的证书与密码

asPool() 设置连接池

withAppleDestination() 是否为开发环境false可发送

最后以build()方法结尾

创建推送参数

PayloadBuilder payloadBuilder = APNS.newPayload();

设置推送标示符: (可以不设置)

customFields() //可以传入map集合

customField() //可以传入key value键值对

设置消息体:传入需要推送的消息

alertBody()

设置app右上角的数字消息数量:

badge()

设置推送消息的铃声:

sound()

发送消息:

service.push(pushToken, payload);

极光推送

Maven依赖:

注意:

极光推送maven依赖如果项目中引用了maven插件需要进行排除,否则项目启动将报错。

<dependency>
   <groupId>cn.jpush.api</groupId>
   <artifactId>jpush-client</artifactId>
   <version>${jpush.version}</version>
   <exclusions>
      <exclusion>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-release-plugin</artifactId>
      </exclusion>
   </exclusions>
</dependency>

极光推送推送类配置

需要开发者账号的appKey Secret

 

 

创建推送类

JPushClient jPushClient = new JPushClient(masterSecret,appKey);

发送消息:

PushResult result = jPushClient.sendPush(payload);

创建推送参数类

PushPayload payload = PushPayload.newBuilder()

设置推送平台:(例如推送给安卓个人用户,设置)

setPlatform(Platform.android_winphone())

设置推送对象:

setAudience(Audience.registrationId("100d8559094fbc0efd4"))

设置通知属性:

setNotification(Notification.newBuilder()
        .setAlert(notification)
        .addPlatformNotification(AndroidNotification.newBuilder()
                .setTitle(title).addExtras(null).build())
        .build())

推送消息内容: setAlert()

添加推送平台通知 例如:设置安卓平台AndroidNotification.newBuilder()

addPlatformNotification(AndroidNotification.newBuilder())

设置标题: setTitle()

添加推送标示符:addExtras() 可以放入map集合 addExtra() 可以放入key value键值对

注意:

推送的主方法中,一般以那个方法的名字开头例如:setNotification(Notification.newBuilder(),以build()方法为结尾。

kaptcha验证码生成

maven依赖

<!-- kaptcha验证码 -->
<dependency>
    <groupId>com.github.axet</groupId>
    <artifactId>kaptcha</artifactId>
    <version>0.0.9</version>
</dependency>

或者(底下需要自己写)

  1. <dependency>  
  2.     <groupId>com.google.code.kaptcha</groupId>  
  3.     <artifactId>kaptcha</artifactId>  
  4.     <version>2.3.2</version>  
  5. </dependency> 

配置web.xml

上面说了,kaptcha都是在web.xml中配置,我们必须在web.xml中配置kaptcha的servlet,具体如下:

<servlet>
   <servlet-name>kaptcha</servlet-name>
   <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
    <init-param> 
           <param-name>kaptcha.border</param-name> 
           <param-value>no</param-value> 
       </init-param> 
       <init-param> 
           <param-name>kaptcha.border.color</param-name> 
           <param-value>105,179,90</param-value> 
       </init-param>      
       <init-param> 
           <param-name>kaptcha.textproducer.font.color</param-name> 
           <param-value>red</param-value> 
       </init-param> 
       <init-param> 
           <param-name>kaptcha.image.width</param-name> 
           <param-value>250</param-value> 
       </init-param> 
       <init-param> 
           <param-name>kaptcha.image.height</param-name> 
           <param-value>90</param-value> 
       </init-param> 
       <init-param> 
           <param-name>kaptcha.textproducer.font.size</param-name> 
           <param-value>70</param-value> 
       </init-param> 

        <!--验证码长度-->
       <init-param> 
           <param-name>kaptcha.textproducer.char.length</param-name> 
           <param-value>4</param-value>
       </init-param> 
       <init-param> 
           <param-name>kaptcha.textproducer.font.names</param-name> 
           <param-value>宋体,楷体,微软雅黑</param-value> 
       </init-param>
   <!-- 全是数字 -->
   <init-param>      
       <param-name>kaptcha.textproducer.char.string</param-name>      
       <param-value>0123456789abcdefghijklmnopqrstuvwxyz</param-value>
   </init-param>
   <!-- 去掉干扰线 -->
       <!--<init-param>-->
       <!--<param-name>kaptcha.noise.impl</param-name>-->
       <!--<param-value>com.google.code.kaptcha.impl.NoNoise </param-value>-->
   <!--</init-param>-->
</servlet>

在jsp页码中:

document.getElementById("img_captcha").src="${ctx}/static/images/kaptcha.jpg?t=" + Math.random();

 

posted on 2017-02-16 18:34  阿发仔  阅读(772)  评论(0编辑  收藏  举报

导航