jnlp的SingleInstanse

//实现SingleInstanceListener接口
class SISListener implements SingleInstanceListener
{
    public void newActivation(String[] params)
    {
        //处理传入参数
    }
}
//获取服务
SingleInstanceService sis; 
try
{ 
    sis = (SingleInstanceService)ServiceManager.lookup("javax.jnlp.SingleInstanceService");
} 
catch (UnavailableServiceException e) 
{ 
    sis=null; 
}
//程序启动时注册SingleInstanceListener
SISListener sisL = new SISListener();
sis.addSingleInstanceListener(sisL);
//程序退出时移除SingleInstanceListener
sis.removeSingleInstanceListener(sisL);
System.exit(0);

Applet自签名

1、修改Applet主Jar包的Manifest文件,添加下面几行,然后重新打包

Application-Name: AppletTest
Implementation-version: 1.0
Application-Library-Allowable-Codebase: *
Permissions: sandbox
Caller-Allowable-Codebase: * localhost 127.0.0.1

2、生成keystore及key

#生成私钥
keytool -validity 10000 -genkey -alias xxxxxx -keypass xxxxxx -storepass xxxxxx -keystore xxxxxx.jks -dname "CN=(R&D),O=(ATS),C=(CN)" -keyalg RSA

导出证书

#证书DER格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -file xxxxxx.der
#证书PEM格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -rfc -file xxxxxx.pem

枚举证书

keytool -list -keystore xxxxxx.jks 

3、签名

jarsigner -keystore xxxxxx.jks -storepass xxxxxx -keypass xxxxxx xxxxxx.jar xxxxxx

4、验证

JARsigner -verbose -verify  xxxxxx.jar

5、信任签名证书,下面两种方式用一种就好了
5.1、导入CA证书(按用OS登录户全局,自签名Jar)

#下面的方式,与java控制面板导入证书效果相同

#win7
keytool -import -trustcacerts -keystore "%userprofile%\AppData\LocalLow\Sun\Java\Deployment\security\trusted.certs" -alias "" -file XXXXXX.cer -storepass "" -noprompt

#winxp
keytool -import -trustcacerts -keystore "%APPDATA%\Sun\Java\Deployment\security\trusted.certs" -alias "" -file XXXXXX.cer -storepass "" -noprompt

5.2、导入CA证书(按JDR/JRE全局,自签名Jar)

keytool -import -trustcacerts -file XXXXXX.der -alias NMyCA1024 -keystore %JRE_HOME%\lib\security\cacerts -storepass changeit

6、如果自签名证书还是不行的话
到java控制面板,安全中,把你的网站添加到信任列表就好了。

Hibernate主键

increment
It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not the used in the clustered environment.

identity
It supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.

sequence
The sequence generator uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int

hilo
The hilo generator uses a hi/lo algorithm to efficiently generate identifiers of type long, short or int, given a table and column (by default hibernate_unique_key and next_hi respectively) as a source of hi values. The hi/lo algorithm generates identifiers that are unique only for a particular database. Do not use this generator with connections enlisted with JTA or with a user-supplied connection.

seqhilo
The seqhilo generator uses a hi/lo algorithm to efficiently generate identifiers of type long, short or int, given a named database sequence.

uuid
The uuid generator uses a 128-bit UUID algorithm to generate identifiers of type string, unique within a network (the IP address is used). The UUID is encoded as a string of hexadecimal digits of length 32.

guid
It uses a database-generated GUID string on MS SQL Server and MySQL.

native
It picks identity, sequence or hilo depending upon the capabilities of the underlying database.

assigned
lets the application to assign an identifier to the object before save() is called. This is the default strategy if no element is specified.

select
retrieves a primary key assigned by a database trigger by selecting the row by some unique key and retrieving the primary key value.

foreign
uses the identifier of another associated object. Usually used in conjunction with a primary key association.

Jar包签名

1、生成keystore及key

#生成私钥
keytool -validity 10000 -genkey -alias xxxxxx -keypass xxxxxx -storepass xxxxxx -keystore xxxxxx.jks -dname "CN=(R&D),O=(ATS),C=(CN)" -keyalg RSA

导出证书

#证书DER格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -file xxxxxx.der
#证书PEM格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -rfc -file xxxxxx.pem

枚举证书

keytool -list -keystore xxxxxx.jks 

2、签名

jarsigner -keystore xxxxxx.jks -storepass xxxxxx -keypass xxxxxx xxxxxx.jar xxxxxx

3、验证

JARsigner -verbose -verify  xxxxxx.jar

struts2返回类型

Chain:
Action响应链,用于多个Action处理一次请求,
后面的Action可以访问前面的Action,不要过度使用

Dispatcher:
网络资源整合,如返回JSP页面,默认

FreeMarker:
用于FreeMarker整合

HttpHeader:
控制特定的HTTP行为

Redirect:
重定向到网络资源

Redirect Action:
重定向到另一个Action映射

Stream:
用于向浏览器提供输入流,一般用于文件下载

Velocity:
用于Velocity整合

XSL:
用于XML/XSLT整合

PlainText:
用于显示页面的原始内容

Tiles:
用于Tiles整合

JAAS配置

1.web.xml

  <!-- JAAS认证 -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>protected-resource</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
      <url-pattern>*.action</url-pattern>
      <http-method>HEAD</http-method>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
      <http-method>PUT</http-method>
      <http-method>DELETE</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>NEOJAAS</role-name>
    </auth-constraint>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
  </login-config>
  <security-role>
    <description>JAASTest Roles</description>
    <role-name>NEOJAAS</role-name>
  </security-role>

2.login.jsp

<form method="post" action="j_security_check"&#93;
  <label>用户名</label>
  <input name="j_username" type="text" maxlength="32" class="login-text"/>
  <label>密&nbsp;&nbsp;&nbsp;码</label>
  <input name="j_password" type="password" maxlength="32" class="login-text"/>
  <input type="submit" class="stuff" value="登&nbsp;录" />
</form>

Tomcat中的Realm

Realm其实就是一个存放用户名,密码及角色的一个“数据库”。
Tomcat中的Realm有下面几种,你也可以使用自己的Realm,只要实现org.apache.catalina.Realm就可以了。

1.JDBCRealm
授权信息存在关系数据库中, 通过JDBC驱动访问
数据库中必须至少有两张表,表示用户及角色
用户表必须至少有两个字段,用户名及密码
角色表必须至少有两个字段,用户名及角色

create table users (
  user_name         varchar(15) not null primary key,
  user_pass         varchar(15) not null
);

create table user_roles (
  user_name         varchar(15) not null,
  role_name         varchar(15) not null,
  primary key (user_name, role_name)
);
<Realm className="org.apache.catalina.realm.JDBCRealm"
  driverName="org.gjt.mm.mysql.Driver"
  connectionURL="jdbc:mysql://localhost/authority?user=dbuser&amp;password=dbpass"
  userTable="users" userNameCol="user_name" userCredCol="user_pass"
  userRoleTable="user_roles" roleNameCol="role_name"/>

2.DataSourceRealm
授权信息存在关系数据库中, 通过JNDI JDBC数据源访问
数据库中必须至少有两张表,表示用户及角色
用户表必须至少有两个字段,用户名及密码
角色表必须至少有两个字段,用户名及角色

create table users (
  user_name         varchar(15) not null primary key,
  user_pass         varchar(15) not null
);

create table user_roles (
  user_name         varchar(15) not null,
  role_name         varchar(15) not null,
  primary key (user_name, role_name)
);
<Realm className="org.apache.catalina.realm.DataSourceRealm"
  dataSourceName="jdbc/authority"
  userTable="users" userNameCol="user_name" userCredCol="user_pass"
  userRoleTable="user_roles" roleNameCol="role_name"/>

3.JNDIRealm
授权信息存在LDAP目录服务器中,通过JNDI提供者访问

<Realm className="org.apache.catalina.realm.JNDIRealm"
  connectionName="cn=Manager,dc=mycompany,dc=com"
  connectionPassword="secret"
  connectionURL="ldap://localhost:389"
  userPassword="userPassword"
  userPattern="uid={0},ou=people,dc=mycompany,dc=com"
  roleBase="ou=groups,dc=mycompany,dc=com"
  roleName="cn"
  roleSearch="(uniqueMember={0})"
/>

4.UserDatabaseRealm
默认配置,只是用于少量用户
授权信息存在用户数据JNDI资源中,该资源通常是一个XML文档 (conf/tomcat-users.xml)

<tomcat-users>
  <user name="tomcat" password="tomcat" roles="tomcat" />
  <user name="role1"  password="tomcat" roles="role1"  />
  <user name="both"   password="tomcat" roles="tomcat,role1" />
</tomcat-users>

5.MemoryRealm
授权信息存在内存中的对象集合中,该对象集合来自XML文档 (conf/tomcat-users.xml).
仅用于测试。

6.JAASRealm
通过JAAS框架访问授权信息,最灵活最开放的一种授权方式。
如果前面几种方式满足不了你的需求,可以先试试这种方式。

<Realm className="org.apache.catalina.realm.JAASRealm"
  appName="MyFooRealm"
  userClassNames="org.foobar.realm.FooUser"
  roleClassNames="org.foobar.realm.FooRole"/>

7.CombinedRealm
采用多种方式授权。

<Realm className="org.apache.catalina.realm.CombinedRealm" >
  <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    resourceName="UserDatabase"/>
  <Realm className="org.apache.catalina.realm.DataSourceRealm"
    dataSourceName="jdbc/authority"
    userTable="users" userNameCol="user_name" userCredCol="user_pass"
    userRoleTable="user_roles" roleNameCol="role_name"/>
</Realm>

8.LockOutRealm
多次登录失败后,锁定用户

<Realm className="org.apache.catalina.realm.LockOutRealm" >
  <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    resourceName="UserDatabase"/>
</Realm>

最后,如果你需要加密密码,那么需要只需要在Realm配置中指定所用的摘要算法就可以了

digest="MD5"
digest="SHA"

参考文章

obj还是objs?

运行下面代码,得到的结果是什么?
obj还是objs?

public class Test{
       public static void test(Object obj){
              System.out.println("obj");
       }
       public static void test(Object[] objs){
              System.out.println("objs");
       }
       public static void main(String[] args){
              test(null);
       }
}

是objs哦:)

JDK命令行

JDKVars.bat

@echo off

set JAVA_HOME=D:\Java\jdk1.6.0_22
set MVN_HOME=D:\Java\apache-maven-3.0.3
set ANT_HOME=D:\Java\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%MVN_HOME%\bin;%ANT_HOME%\bin;%PATH%
set CLASSPATH=.;%JAVA_HOME%\lib\tools.jar

color 02
title Java_1.6_u22
echo Java_Enviroment_OK!

echo on

cmd快捷启动方式

%ComSpec% /K D:\Java\jdk1.6.0_22\bin\JDKVars.bat