2009年12月24日星期四
2009年11月22日星期日
chrome os 虚拟机 试用
1.down下来达人们制作的虚拟机镜像文件 chromeos-image-999.999.32309.211410-a1.vmdk.bz2 ,网上一搜一堆;
2.用vmware player直接打开,或者用virtualBox打开(新建虚拟机-类型linux(ubuntu)-使用已有虚拟机硬盘,即.vmdk文件-完成)
3.进入,联网情况下输入自己的gmail帐号或直接输入用户名mark,密码为空。
----------------------------------------------------------- 免责声明(Disclaimer): 1.此电子邮件包含来自神州数码的信息,而且是机密的或者专用的信息。这些信息是供所有以上列出的个人或者团体使用的。如果您不是此邮件的预期收件人,请勿阅读、复制、转发或存储此邮件。如果已误收此邮件,请通知发件人。 This e-mail may contain confidential and/or privileged information from Digital China and is intended solely for the attention and use of the person(s) named above. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden. 2.本公司不担保本电子邮件中信息的准确性、适当性或完整性,并且对此产生的任何错误或疏忽不承担任何责任。 The content provided in this e-mail can not be guaranteed and assured to be accurate, appropriate for all, and complete by Digital China, and Digital China can not be held responsible for any error or negligence derived therefrom. 3.接收方应在接收电子邮件或任何附件时检查有无病毒。本公司对由于转载本电子邮件而引发病毒产生的任何损坏不承担任何责任。 The internet communications through this e-mail can not be guaranteed or assured to be error or virus-free, and the sender do not accept liability for any errors, omissions or damages arising therefrom.
2009年7月4日星期六
java字符串分隔符split/StringTokenizer
<!>比较两种表示法
利用split函数:
1. String s = new String("2_8_7_4_3_9_1");
2. String[] arr = s.split("_");
●利用StringTokenizer类:
1. String s = new String("2_8_7_4_3_9_1");
2. StringTokenizer commaToker = new StringTokenizer(s, "_");
3. String[] arr = new String[commaToker.countTokens()];
<2>split用法详解
在java.lang包中有String.split()方法,返回是一个数组
我在应用中用到一些,给大家总结一下,仅供大家参考:
1、如果用"."作为分隔的话,必须是如下写法:String.split("\\."),这样才能正确的分隔开,不能用String.split(".");
2、如果用"|"作为分隔的话,必须是如下写法:String.split("\\|"),这样才能正确的分隔开,不能用String.split("|");
"."和"|"都是转义字符,必须得加"\\";
3、如果在一个字符串中有多个分隔符,可以用"|"作为连字符,比如:"acount=? and uu =? or n=?",把三个都分隔出来,可以用String.split("and|or");
测试程序如下:
public class StringSplit {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String a="acount=? and uu =? or n=?";
String b[]=a.split("and|or");
for(int i=0;i<=b.length;i++)
{
System.out.println(b[i]);
}
}
}
输出结果:
acount=?
uu =?
n=?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at com.ljj.string.StringSplit.main(StringSplit.java:14)
分析 Tomcat catalina.bat 脚本
首先省去catalina.bat开头诸多注解,这些注解主要是讲解各个变量是干什么的。需要的话,自己看下英文就可以了。这里就不翻译了。
rem Guess CATALINA_HOME if not defined 查看是否在tomcat目录下,与startup.bat里相同,不解释了。需要的话可以看我的另一篇博客。
set CURRENT_DIR=%cd%
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=%CURRENT_DIR%
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set CATALINA_HOME=%cd%
cd %CURRENT_DIR%
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
rem Get standard environment variables
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat" 如果存在setenv.bat脚本,调用它,我的tomcat 没有这个脚本
rem Get standard Java environment variables
if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath 查看是否存在setclasspath.bat脚本,如果存在,转到okSetclasspath位置
echo Cannot find %CATALINA_HOME%\bin\setclasspath.bat 否则输出下面两行,并退出
echo This file is needed to run this program
goto end
:okSetclasspath okSetclasspath位置
set BASEDIR=%CATALINA_HOME% 设定BASEDIR变量与CATALINA_HOME变量值相同
call "%CATALINA_HOME%\bin\setclasspath.bat" %1 调用setclasspath.bat脚本并加上参数
if errorlevel 1 goto end 如果存在错误 退出
rem Add on extra jar files to CLASSPATH 设定JSSE_HOME变量,如果存在加入CLASSPATH,不存在跳过
if "%JSSE_HOME%" == "" goto noJsse 检查是否存在JSSE_HOME变量
set CLASSPATH=%CLASSPATH%;%JSSE_HOME%\lib\jcert.jar;%JSSE_HOME%\lib\jnet.jar;%JSSE_HOME%\lib\jsse.jar 如果有加入到CLASSPATH变量后面
:noJsse
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\bootstrap.jar 将bootstrap.jar加入到CLASSPATH里
if not "%CATALINA_BASE%" == "" goto gotBase 如果CATALINA_BASE变量不为空,跳过,转到gotBase位置
set CATALINA_BASE=%CATALINA_HOME% 如果为空,将CATALINA_BASE设为CATALINA_HOME变量的值
:gotBase
if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir CATALINA_TMPDIR不为空,跳过,转到gotTmpdir位置
set CATALINA_TMPDIR=%CATALINA_BASE%\temp 如果为空,将 CATALINA_TMPDIR设为%CATALINA_BASE%\temp变量的值(即tomcat\temp)
:gotTmpdir
if not exist "%CATALINA_HOME%\bin\tomcat-juli.jar" goto noJuli 如果不存在tomcat-juli.jar这个类,转到noJuli位置
set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager - Djava.util.logging.config.file="%CATALINA_BASE%\conf \logging.properties" 如果存在,将变量加入到JAVA_OPTS里
:noJuli
set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -Dfile.encoding=UTF8 -Duser.timezone=GMT -Djava.security.auth.login.config=%CATALINA_HOME%/conf /jaas.config 设定JAVA_OPTS变量
echo Using CATALINA_BASE: %CATALINA_BASE% 输出CATALINA_BASE变量值
echo Using CATALINA_HOME: %CATALINA_HOME% 输出CATALINA_HOME变量值
echo Using CATALINA_TMPDIR: %CATALINA_TMPDIR% 输出CATALINA_TMPDIR变量值
if ""%1"" == ""debug"" goto use_jdk 如果变量%1里存在debug ,转到use_jdk位置
echo Using JRE_HOME: %JRE_HOME% 输出JRE_HOME变量值
goto java_dir_displayed 转到java_dir_displayed
:use_jdk
echo Using JAVA_HOME: %JAVA_HOME% 输出JAVA_HOME变量值
:java_dir_displayed
下面几行设定相应变量
set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=
if not ""%1"" == ""jpda"" goto noJpda
set JPDA=jpda
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
set JPDA_TRANSPORT=dt_shmem
:gotJpdaTransport
if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=jdbconn
:gotJpdaAddress
if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
set JPDA_SUSPEND=n
:gotJpdaSuspend
if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
set JPDA_OPTS=-Xdebug -Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
:gotJpdaOpts
shift
:noJpda
if ""%1"" == ""debug"" goto doDebug 如果%1为debug,转到doDebug,运行debug模式
if ""%1"" == ""run"" goto doRun 如果%1为run,转到doRun,运行正常模式
if ""%1"" == ""start"" goto doStart 如果%1为start,转到doStart,启动tomcat
if ""%1"" == ""stop"" goto doStop 如果%1为stop,转到doStop,关闭tocmat
if ""%1"" == ""version"" goto doVersion 如果%1为version,转到doVersion,显示tomcat的版本号
echo Usage: catalina ( commands ... ) 如果%1没有上述内容,输出下面几行,并结束
echo commands:
echo debug Start Catalina in a debugger
echo debug -security Debug Catalina with a security manager
echo jpda start Start Catalina under JPDA debugger
echo run Start Catalina in the current window
echo run -security Start in the current window with security manager
echo start Start Catalina in a separate window
echo start -security Start in a separate window with security manager
echo stop Stop Catalina
echo version What version of tomcat are you running?
goto end
:doDebug
shift 将%2里的值转到%1
set _EXECJAVA=%_RUNJDB% 将变量 _EXECJAVA设为_RUNJDB变量的值
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\jakarta-tomcat-catalina\catalina\src\share"
设定DEBUG_OPTS变量
if not ""%1"" == ""-security"" goto execCmd
如果%1不为-security,转到execCmd位置
shift 将%2里的值转到%1
echo Using Security Manager 输出该行
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
设定SECURITY_POLICY_FILE变量的值
goto execCmd 转到execCmd位置
:doRun
shift 将%2里的值转到%1
if not ""%1"" == ""-security"" goto execCmd 如果%1不为-security,转到execCmd位置
shift 将%2里的值转到%1
echo Using Security Manager 输出该行
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
设定SECURITY_POLICY_FILE变量的值
goto execCmd 转到execCmd位置
:doStart
shift 将%2里的值转到%1
if not "%OS%" == "Windows_NT" goto noTitle 如果OS变量不为Windows_NT,转到noTitle
set _EXECJAVA=start "Tomcat" %_RUNJAVA% 设定_EXECJAVA变量的值
goto gotTitle 转到gotTitle位置
:noTitle
set _EXECJAVA=start %_RUNJAVA% 设定 _EXECJAVA 变量的值
:gotTitle
if not ""%1"" == ""-security"" goto execCmd 如果%1不为-security,转到execCmd位置
shift 将%2里的值转到%1
echo Using Security Manager 输出该行
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
设定SECURITY_POLICY_FILE变量的值
goto execCmd 转到execCmd位置
:doStop
shift 将%2里的值转到%1
set ACTION=stop 将ACTION的变量设为stop
set CATALINA_OPTS= 设CATALINA_OPTS为空
200万种商品,最低价格,疯狂诱惑你
2009年7月3日星期五
Struts2+Spring+Hibernate搭建全解
Struts2+Spring+Hibernate是J2EE的最新流行框架。本篇是我搭建这个框架的经验总结,有很多人搭建这个框架总会遇到
大大小小的问题,网上也没有什么行之有效的方案或成体系的介绍,所以我就决定总结一下我的搭建过程。给一些搭
建尚存问题的朋友提供帮助。
我用这个框架,实现的是基本的CRUD功能的一个雇员管理系统,本来打算丰富一下功能,但是一直没能抽出空去搞。
目前版本暂定为1.0,除了CRUD外还配置了表单验证框架JSValidation。功能都能很顺利的实现。
现在分享部分源码,来说明一些注意事项。
以下是部分搭建过程及源码:
1.先组合实现Hibernate3.2+Spring2.5支持,删除hibernate.cfg.xml文件,修改applicationContext.xml文件的内容,增加SessionFactory和dataSource的设置。
2.通过MyEclipse的向导方式,生成POJO类和对应的映射文件。
3.修改applicationContext.xml文件中<property name="mappingResources">元素的内容。
4.编写DAO接口和实现类。
5.修改applicationContext.xml文件,增加对Dao实现类的配置。
6.组合Struts2和Spring2.5,修改web.xml文件,增加struts2的所需要的过滤器配置。
7.增加struts2相应类库,增加struts2与spring的配置jar包。
8.拷贝struts.xml文件到src根目录下,再修改struts.xml文件,进行常量配置。
9.修改web.xml文件,配置Spring监听器,和上下文变量。并增加OpenSessionInViewFilter的设置。
10.写入action类。
11.配置struts.xml文件。
12.修改applicationContext.xml
13.编写Jsp文件。
14.加载运行项目。
下面是关键文件的源码:
struts.xml源码:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- struts2委托spring管理 -->
<constant name="struts.objectFactory" value="spring"/>
<!-- /crm/emp/add.action -->
<package name="crm_employee" extends="struts-default" namespace="/emp">
<action name="add" class="addBean" method="add">
<result>add.action</result>
<result>/emp/add_suc.jsp</result>
</action>
<action name="list" class="listBean" method="list">
<result>/emp/list.jsp</result>
</action>
<action name="delete" class="deleteBean" method="delete">
<result>delete.action</result>
<result>/emp/delete_suc.jsp</result>
</action>
<action name="update" class="updateBean" method="update">
<result>update.action</result>
<result>/emp/edit_suc.jsp</result>
</action>
<action name="edit" class="editBean" method="edit">
<result>/emp/edit.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
web.xml源码:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<!-- 开启监听 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 配置OpenSessionInViewFilter,必须在struts2监听之前 -->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<!-- 设置监听加载上下文 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml源码:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 配置Hibernate支持 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/tables">
</property>
<property name="username" value="root"></property>
<property name="password" value="hicc"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/sy/crm/model/Employee.hbm.xml</value>
</list>
</property>
</bean>
<bean id="employeeDao"
class="com.sy.crm.dao.hibernate.EmployeeDaoHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="employeeManager"
class="com.sy.crm.service.impl.EmployeeManagerImpl">
<property name="employeeDao">
<ref bean="employeeDao" />
</property>
</bean>
<bean id="addBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="listBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="deleteBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="updateBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="editBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事务特性,配置add,delete,update开始的方法,事务传播特性为required -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理,当前com.sy.crm.service包中的子包,
类中所有方法需要,还需要参考tx:advice的设置 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(*
com.sy.crm.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>add page</title>
<script language="JavaScript" src="validation-framework.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center>
<h3>雇员注册:</h3><br>
<h4><a href="../emp/list.action">查看所有雇员</a></h4>
<div id="error" style="color:blue; font-weight:bold;"></div>
<s:form action="add" method="post" onsubmit="return doValidate('form')" name="form" id="form">
<s:textfield name="employee.name" label="姓名" id="name"/>
<s:textfield name="employee.address" label="地址"/>
<s:textfield name="employee.phone" label="电话"/>
<s:submit value="员工注册"/>
</s:form>
</center>
</body>
</html>
list.jsp源码:
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>list employee page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
table thead tr th {
border: 1px solid black;
padding: 3px;
background-color: #cccccc;
}
table tbody tr td {
border: 1px solid black;
padding: 3px;
}
</style>
</head>
<body>
<center>
<h3>
雇员管理:
</h3>
<br>
<h4>
<a href="../emp/add.jsp">员工注册</a>
</h4>
<s:form action="delete" theme="simple">
<table>
<thead>
<tr>
<th>
选择
</th>
<th>
编号
</th>
<th>
姓名
</th>
<th>
电话
</th>
<th>
地址
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<s:iterator value="employees">
<tr>
<td>
<input type="checkbox" name="id"
value='<s:property value="id" />' />
</td>
<td>
<s:property value="id" />
</td>
<td>
<s:property value="name" />
</td>
<td>
<s:property value="phone" />
</td>
<td>
<s:property value="address" />
</td>
<td>
<a
href='<s:url action="edit"><s:param name="id" value="id" /></s:url>'>
修改 </a>
<a
href='<s:url action="delete"><s:param name="id" value="id" /></s:url>'>
删除 </a>
</td>
</tr>
</s:iterator>
</tbody>
</table>
<s:submit value="delete" />
</s:form>
</center>
</body>
</html>
第一点注意的是,搭建出项目,一定会报错,因为Spring 2.5 AOP Libraries中的asm的三个jar包会和
Hibernate 3.2 Core Libraries中的asm的jar包中的某些类中有冲突。所以一定要删除Spring中的三个asm的jar包。
第二点要注意的是,struts2的配置包的导入,需要的是5个jar包分别是:
struts2-core-2.0.11.2.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
xwork-2.05.jar
commons-logging-1.0.4.jar
struts2+spring配置包:struts2-spring-plugin-2.0.11.2.jar
网上有些还说需要把4个spring的包拷到lib下,我是拷了但是,并不确定这样做是否有必要。
总之是正常运行了。
所以也就没想太多。如果有的朋友运行不了,可以考虑把这4个需要的包写上来。
好了就说这么多吧,有疑问的朋友可以留言。我会尽量答复。