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

1和0

下面语句会出错吗?
你感觉哪一句不会出错呢?

public class Test01
{
    public static void main(String[] atgs)
    {
        System.out.println(1.0/0.0);
        System.out.println(1.0/0);
        System.out.println(1/0.0);
        System.out.println(1/0);
        System.out.println(0/0);
    }
}

你对java中的无穷大和非数了解吗?

Jboss4.2.3GA与Asix2通讯失败

两个项目,分别使用Jboss和Asix2开发了webservice及其client,通讯走的是soap1.2

最后用客户端访问服务端时,却发现Jboss的客户端,可以分别访问Jboss及Asix2的服务端
但Asix2的服务端却只能访问Asix2的服务端,访问Jboss的服务端时,会报下面的错误:
Transport level information does not match with SOAP Message namespace URI

经过跟踪Asix2的源码,并截取双方的通信内容,发现,
原来JBoss4.2.3GA返回消息时,没有按照soap1.2标准,返回正确的HTTP消息头
在Content-Type中,start-info无论如何只会填写text/xml,这和SOAP1.2要求的application/soap+xml是不一致的。

在JBoss网站发现,JBoss4.3以上的版本修复了这个问题,但4.3以上是收费的。
咋办啊,只好自己打补丁咯
下载jbossws-core源码包,按照下面的补丁内容,改好文件
https://issues.jboss.org/secure/attachment/12323928/JBWS-2419_patch.txt
重新打好jar包,替换过去
搞定:)