﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-I love Java</title><link>http://www.blogjava.net/yruc/</link><description>java</description><language>zh-cn</language><lastBuildDate>Wed, 15 Apr 2026 14:17:38 GMT</lastBuildDate><pubDate>Wed, 15 Apr 2026 14:17:38 GMT</pubDate><ttl>60</ttl><item><title>java获取当前系统时间</title><link>http://www.blogjava.net/yruc/archive/2008/07/14/214766.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Mon, 14 Jul 2008 08:45:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2008/07/14/214766.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/214766.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2008/07/14/214766.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/214766.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/214766.html</trackback:ping><description><![CDATA[import java.util.Date;<br />
import java.util.Calendar;<br />
import java.text.SimpleDateFormat;<br />
<br />
public class SystemTime<br />
{<br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args)<br />
&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Calendar cal=Calendar.getInstance();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //-200代表200天前这个时候的时间<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cal.add(Calendar.DAY_OF_YEAR,-200);<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nowtime=sdf.format(cal.getTime());<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println(nowtime);<br />
&nbsp;&nbsp;&nbsp; }<br />
}
<img src ="http://www.blogjava.net/yruc/aggbug/214766.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2008-07-14 16:45 <a href="http://www.blogjava.net/yruc/archive/2008/07/14/214766.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批处理常用命令及用法大全</title><link>http://www.blogjava.net/yruc/archive/2008/01/07/173297.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Mon, 07 Jan 2008 04:24:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2008/01/07/173297.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/173297.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2008/01/07/173297.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/173297.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/173297.html</trackback:ping><description><![CDATA[<h2>&nbsp;</h2>
<div class="t_msgfont" id="postmessage_78"><br />
<br />
阅读本文需要一定的dos基础概念，象：盘符、文件、目录(文件夹)、子目录、根目录、当前目录<br />
每个命令的完整说明请加 /? 参数参考微软的帮助文档可以看到，在 /? 帮助里，"命令扩展名"一词会经常出现"命令扩<br />
<br />
展名"是指相对于win98的dos版本而言，每个命令新增的功能<br />
命令测试环境win2000proSP4win98的命令功能太少，就不作研究了<br />
<br />
注：如果对某一命令还不是很熟悉，可以在命令行窗口下输入：命令名/?的方式来获得帮助。<br />
例如：对dir命令的应用不熟悉，可以在命令行窗口下输入：<br />
<br />
dir /?<br />
<br />
1 echo 和 @回显控制命令<br />
@&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#关闭单行回显<br />
echo off&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #从下一行开始关闭回显<br />
@echo off&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#从本行开始关闭回显。一般批处理第一行都是这个<br />
echo on&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#从下一行开始打开回显<br />
echo&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示当前是 echo off 状态还是 echo on 状态<br />
echo.&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #输出一个"回车换行"，一般就是指空白行<br />
echo hello world&nbsp; &nbsp;&nbsp;&nbsp;#输出hello world<br />
"关闭回显"是指运行批处理文件时，不显示文件里的每条命令，只显示运行结果批处理开始和结束时，系统都会自动打开<br />
<br />
回显<br />
2 errorlevel程序返回码<br />
<br />
echo %errorlevel%每个命令运行结束，可以用这个命令行格式查看返回码用于判断刚才的命令是否执行成功默认值为0，<br />
<br />
一般命令执行出错会设 errorlevel 为1<br />
<br />
3 dir显示目录中的文件和子目录列表<br />
dir&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示当前目录中的文件和子目录<br />
dir /a&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示当前目录中的文件和子目录，包括隐藏文件和系统文件<br />
dir c: /a:d&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示 C 盘当前目录中的目录<br />
dir c:\ /a:-d&nbsp; &nbsp;&nbsp; &nbsp; #显示 C 盘根目录中的文件dir d:\mp3 /b/p&nbsp; &nbsp;&nbsp;&nbsp;#逐屏显示 d:\mp3 目录里的文件，只显示文件<br />
<br />
名，不显示时间和大小<br />
dir *.exe /s显示当前目录和子目录里所有的.exe文件其中 * 是通配符，代表所有的文件名，还一个通配符 ? 代表一个<br />
<br />
任意字母或汉字如 c*.* 代表以 c 开头的所有文件?.exe 代表所有文件名是一个字母的.exe文件如果指定的目录或文件<br />
<br />
不存在，将返回 errorlevel 为1;每个文件夹的 dir 输出都会有2个子目录 . 和 ... 代表当前目录.. 代表当前目录的<br />
<br />
上级目录<br />
dir .&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示当前目录中的文件和子目录<br />
dir ..&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示当前目录的上级目录中的文件和子目录<br />
其它参数可参考 dir /?<br />
<br />
4 cd更改当前目录<br />
cd mp3&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#进入当前目录中的mp3 目录<br />
cd ..&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#进入当前目录中的上级目录<br />
cd\&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#进入根目录<br />
cd&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示当前目录<br />
cd /d d:\mp3&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#可以同时更改盘符和目录<br />
cd "Documents and Settings"\All users文件名带空格，路径前需要加上引号！！如果更改到的目录不存在，则出错返<br />
<br />
回 errorlevel=1<br />
<br />
5 md创建目录<br />
md abc&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#在当前目录里建立子目录 abc<br />
md d:\a\b\c&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#如果 d:\a 不存在，将会自动创建<br />
<br />
6 rd删除目录<br />
rd abc&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#删除当前目录里的 abc 子目录，要求为空目录<br />
rd /s/q d:\temp&nbsp; &nbsp;&nbsp;&nbsp;#删除 d:\temp 文件夹及其子文件夹和文件，不需要按 Y 确认<br />
<br />
7 del删除文件<br />
del d:\test.txt&nbsp; &nbsp;&nbsp;&nbsp;#删除指定文件，不能是隐藏、系统、只读文件<br />
del *.*删除当前目录里的所有文件，不包括隐藏、系统、只读文件，要求按 Y 确认<br />
del /q/a/f d:\temp\*.*删除 d:\temp 文件夹里面的所有文件，包括隐藏、只读、系统文件，不包括子目录<br />
del /q/a/f/s d:\temp\*.*删除 d:\temp 及子文件夹里面的所有文件，包括隐藏、只读、系统文件，不包括子目录<br />
<br />
8 ren文件重命名<br />
ren 1.txt 2.bak&nbsp; &nbsp;&nbsp;&nbsp;#把 1.txt 更名为 2.bak<br />
ren *.txt *.ini&nbsp; &nbsp;&nbsp;&nbsp;#把当前目录里所有.txt文件改成.ini文件<br />
ren d:\temp tmp&nbsp; &nbsp;&nbsp;&nbsp;#支持对文件夹的重命名<br />
<br />
9 cls清屏<br />
<br />
10 type显示文件内容<br />
type c:\boot.ini&nbsp; &nbsp; #显示指定文件的内容，程序文件一般会显示乱码<br />
type *.txt&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示当前目录里所有.txt文件的内容<br />
<br />
11 copy拷贝文件<br />
copy c:\test.txt d:\复制 c:\test.txt 文件到 d:\<br />
copy c:\test.txt d:\test.bak复制 c:\test.txt 文件到 d:\ ，并重命名为 test.bak<br />
copy c:\*.*复制 c:\ 所有文件到当前目录，不包括隐藏文件和系统文件不指定目标路径，则默认目标路径为当前目录<br />
copy con test.txt从屏幕上等待输入，按 Ctrl+Z 结束输入，输入内容存为test.txt文件con代表屏幕，prn代表打印机<br />
<br />
，nul代表空设备<br />
copy 1.txt + 2.txt 3.txt合并 1.txt 和 2.txt 的内容，保存为 3.txt 文件如果不指定 3.txt ，则保存到 1.txt<br />
copy test.txt +复制文件到自己，实际上是修改了文件日期<br />
<br />
12 title设置cmd窗口的标题<br />
title 新标题&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#可以看到cmd窗口的标题栏变了<br />
<br />
13 ver显示系统版本<br />
<br />
14 label 和 vol设置卷标<br />
vol&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示卷标<br />
label&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示卷标，同时提示输入新卷标<br />
label c:system&nbsp; &nbsp;&nbsp; &nbsp;#设置C盘的卷标为 system<br />
<br />
15 pause暂停命令<br />
运行该命令时，将显示下面的消息：请按任意键继续 . . .<br />
一般用于看清楚屏幕上显示的内容<br />
<br />
16 rem 和 ::注释命令<br />
注释行不执行操作<br />
<br />
17 date 和 time日期和时间<br />
date&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示当前日期，并提示输入新日期，按"回车"略过输入<br />
date/t&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#只显示当前日期，不提示输入新日期<br />
time&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示当前时间，并提示输入新时间，按"回车"略过输入<br />
time/t&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#只显示当前时间，不提示输入新时间<br />
<br />
18 goto 和 :跳转命令<br />
:label&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#行首为:表示该行是标签行，标签行不执行操作<br />
goto label&nbsp; &nbsp; #跳转到指定的标签那一行<br />
<br />
19 find (外部命令)查找命令<br />
find "abc" c:\test.txt在 c:\test.txt 文件里查找含 abc 字符串的行如果找不到，将设 errorlevel 返回码为1<br />
find /i "abc" c:\test.txt查找含 abc 的行，忽略大小写<br />
find /c "abc" c:\test.txt显示含 abc 的行的行数<br />
<br />
20 more (外部命令)逐屏显示<br />
more c:\test.txt&nbsp; &nbsp; #逐屏显示 c:\test.txt 的文件内容<br />
<br />
21 tree显示目录结构<br />
tree d:\&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示D盘的文件目录结构<br />
<br />
22 &amp;顺序执行多条命令，而不管命令是否执行成功<br />
c: &amp; cd\ &amp; dir /w相当于把下面3行命令写到1行去了c:cd\dir /w<br />
<br />
23 &amp;&amp;顺序执行多条命令，当碰到执行出错的命令后将不执行后面的命令<br />
f: &amp;&amp; cd\ &amp;&amp; dir &gt;c:\test.txt注意如果f盘不存在，那么后面2条命令将不会执行<br />
find "ok" c:\test.txt &amp;&amp; echo 成功如果找到了"ok"字样，就显示"成功"，找不到就不显示<br />
<br />
24 ||顺序执行多条命令，当碰到执行正确的命令后将不执行后面的命令<br />
<br />
find "ok" c:\test.txt || echo 不成功如果找不到"ok"字样，就显示"不成功"，找到了就不显示<br />
<br />
25 |管道命令<br />
前一个命令的执行结果输出到后一个命令<br />
dir *.* /s/a | find /c ".exe"管道命令表示先执行 dir 命令，对其输出的结果执行后面的 find 命令该命令行结果：<br />
<br />
输出当前文件夹及所有子文件夹里的.exe文件的个数<br />
type c:\test.txt|more这个和 more c:\test.txt 的效果是一样的<br />
<br />
26 &gt; 和 &gt;&gt;输出重定向命令<br />
&gt; 清除文件中原有的内容后再写入&gt;&gt; 追加内容到文件末尾，而不会清除原有的内容主要将本来显示在屏幕上的内容输出<br />
<br />
到指定文件中指定文件如果不存在，则自动生成该文件<br />
echo hello world&gt;c:\test.txt生成c:\test.txt文件，内容为hello world这个格式在批处理文件里用得很多，可以生成 <br />
<br />
.reg .bat .vbs 等临时文件<br />
type c:\test.txt &gt;prn屏幕上不显示文件内容，转向输出到打印机<br />
echo hello world&gt;con在屏幕上显示hello world，实际上所有输出都是默认 &gt;con 的<br />
copy c:\test.txt f: &gt;nul拷贝文件，并且不显示"文件复制成功"的提示信息，但如果f盘不存在，还是会显示出错信息<br />
copy c:\test.txt f: &gt;nul 2&gt;nul不显示"文件复制成功"的提示信息，并且f盘不存在的话，也不显示错误提示信息<br />
echo ^^W ^&gt; ^W&gt;c:\test.txt生成的文件内容为 ^W &gt; W^ 和 &gt; 是控制命令，要把它们输出到文件，必须在前面加个 ^ <br />
<br />
符号<br />
27 &lt;从文件中获得输入信息，而不是从屏幕上<br />
一般用于 date time label 等需要等待输入的命令<br />
@echo offecho 2005-05-01&gt;temp.txtdate &lt;temp.txtdel temp.txt这样就可以不等待输入直接修改当前日期<br />
<br />
28 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %*命令行传递给批处理的参数<br />
%0 批处理文件本身%1 第一个参数%9 第九个参数%* 从第一个参数开始的所有参数<br />
在C盘根目录新建test.bat，内容如下：<br />
@echo offecho %0echo %1echo %2echo %*<br />
运行cmd，输入 c:\test.bat "/a" /b /c /d可以看出每个参数的含意<br />
修改test.bat内容如下<br />
@echo offecho %1echo %~1echo %0echo %~f0echo %~d0echo %~p0echo %~n0echo %~x0echo %~s0echo %~a0echo %<br />
<br />
~t0echo %~z0<br />
再运行cmd，输入 c:\test.bat "/a" /b /c /d可以参照 call/? 或 for/? 看出每个参数的含意注意这里可以对文件进行<br />
<br />
日期比较和大小比较<br />
echo load "%%1" "%%2"&gt;c:\test.txt生成的文件内容为 load "%1" "%2"批处理文件里，用这个格式把命令行参数输出到<br />
<br />
文件<br />
<br />
31 set设置变量<br />
引用变量可在变量名前后加 % ，即 %变量名%<br />
set&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示目前所有可用的变量，包括系统变量和自定义的变量<br />
echo %SystemDrive%&nbsp; &nbsp;&nbsp;&nbsp;#显示系统盘盘符。系统变量可以直接引用<br />
set p&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示所有以p开头的变量，要是一个也没有就设errorlevel=1<br />
set p=aa1bb1aa2bb2&nbsp; &nbsp;&nbsp;&nbsp;#设置变量p，并赋值为 = 后面的字符串，即aa1bb1aa2bb2<br />
echo %p%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示变量p代表的字符串，即aa1bb1aa2bb2<br />
echo %p:~6%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示变量p中第6个字符以后的所有字符，即aa2bb2<br />
echo %p:~6,3%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示第6个字符以后的3个字符，即aa2<br />
echo %p:~0,3%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示前3个字符，即aa1<br />
echo %p:~-2%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示最后面的2个字符，即b2<br />
echo %p:~0,-2%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#显示除了最后2个字符以外的其它字符，即aa1bb1aa2b<br />
echo %p:aa=c%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #用c替换变量p中所有的aa，即显示c1bb1c2bb2<br />
echo %p:aa=%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#将变量p中的所有aa字符串置换为空，即显示1bb12bb2<br />
echo %p:*bb=c%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#第一个bb及其之前的所有字符被替换为c，即显示c1aa2bb2<br />
set p=%p:*bb=c%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#设置变量p，赋值为 %p:*bb=c% ，即c1aa2bb2<br />
set /a p=39&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#设置p为数值型变量，值为39<br />
set /a p=39/10&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#支持运算符，有小数时用去尾法，39/10=3.9，去尾得3，p=3set /a p=p/10&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #用 /a <br />
<br />
参数时，在 = 后面的变量可以不加%直接引用set /a p="1&amp;0"&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#"与"运算，要加引号。其它支持的运算符参见<br />
<br />
set/?<br />
set p=&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#取消p变量<br />
set /p p=请输入屏幕上显示"请输入"，并会将输入的字符串赋值给变量p注意这条可以用来取代 choice 命令<br />
注意变量在 if 和 for 的复合语句里是一次性全部替换的，如<br />
@echo off<br />
set p=aaa<br />
if %p%==aaa (&nbsp; &nbsp; <br />
&nbsp;&nbsp;echo %p%&nbsp; &nbsp;<br />
&nbsp;&nbsp;set p=bbb&nbsp; &nbsp; <br />
&nbsp;&nbsp;echo %p%&nbsp; &nbsp; )<br />
结果将显示aaaaaa因为在读取 if 语句时已经将所有 %p% 替换为aaa这里的"替换"，在 /? 帮助里就是指"扩充"、"环境<br />
<br />
变量扩充"可以启用"延缓环境变量扩充"，用 ! 来引用变量，即 !变量名!<br />
@echo off<br />
SETLOCAL ENABLEDELAYEDEXPANSION<br />
set p=aaaif %p%==aaa (&nbsp;&nbsp;<br />
&nbsp;&nbsp;echo %p%&nbsp; &nbsp; <br />
set p=bbb&nbsp; &nbsp; <br />
echo !p!&nbsp; &nbsp; )<br />
ENDLOCAL<br />
结果将显示aaabbb<br />
还有几个动态变量，运行 set 看不到<br />
%CD%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#代表当前目录的字符串<br />
%DATE%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #当前日期<br />
%TIME%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #当前时间<br />
%RANDOM%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#随机整数，介于0~32767<br />
%ERRORLEVEL%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #当前ERRORLEVEL 值<br />
%CMDEXTVERSION%&nbsp; &nbsp;&nbsp; &nbsp; #当前命令处理器扩展名版本号<br />
%CMDCMDLINE%&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #调用命令处理器的原始命令行可以用echo命令查看每个变量值，如 echo %time%注意 %time% <br />
<br />
精确到毫秒，在批处理需要延时处理时可以用到<br />
<br />
32 start批处理中调用外部程序的命令，否则等外部程序完成后才继续执行剩下的指令<br />
start explorer d:\调用图形界面打开D盘<br />
@echo offcd /d %~dp0regedit /s 劲舞团.regstart patcher.exe<br />
不加 start 命令的话，"劲舞团"运行时，后面会有个黑乎乎的cmd窗口<br />
<br />
33 call批处理中调用另外一个批处理的命令，否则剩下的批处理指令将不会被执行有时有的应用程序用start调用出错的<br />
<br />
，也可以call调用<br />
<br />
34 choice (外部命令)选择命令让用户输入一个字符，从而选择运行不同的命令，返回码errorlevel为1234&#8230;&#8230;win98里<br />
<br />
是choice.comwin2000pro里没有，可以从win98里拷过来win2003里是choice.exechoice /N /C y /T 5 /D y&gt;nul延时5秒<br />
<br />
下面是个 choice 语句的例子<br />
@echo off<br />
rem 以下在win2000pro运行通过，从win98里拷的chioce.com文件<br />
choice /c:abc aaa,bbb,ccc<br />
if errorlevel 3 goto ccc<br />
if %errorlevel%==2 goto bbb<br />
if errorlevel==1 goto aaa<br />
rem 必须先判断数值高的返回码rem 可以看到 errorlevel 值的判断有3种写法，有时某种写法不好用，可以用另外的写法<br />
rem 直接运行<br />
<br />
chioce相当于运行<br />
choice /c:yn:aaa<br />
echo aaa<br />
goto end<br />
:bbb<br />
echo bbb<br />
goto end<br />
:ccc<br />
echo ccc<br />
goto end<br />
:end<br />
<br />
35 assoc 和 ftype文件关联assoc 设置'文件扩展名'关联，关联到'文件类型'ftype 设置'文件类型'关联，关联到'执行程序和参数'当你双击一个.txt文件时，windows并不是根据.txt直接判断用 notepad.exe 打开而是先判断.txt属于 txtfile '文件类型'再调用 txtfile 关联的命令行 txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1可以在"文件夹选项"&#8594;"文件类型"里修改这2种关联<br />
assoc&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示所有'文件扩展名'关联<br />
assoc .txt&nbsp; &nbsp;&nbsp; &nbsp;#显示.txt代表的'文件类型'，结果显示 .txt=txtfile<br />
assoc .doc&nbsp; &nbsp;&nbsp; &nbsp;#显示.doc代表的'文件类型'，结果显示 .doc=Word.Document.8<br />
assoc .exe&nbsp; &nbsp;&nbsp; &nbsp;#显示.exe代表的'文件类型'，结果显示 .exe=exefile<br />
ftype&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#显示所有'文件类型'关联<br />
ftype exefile&nbsp; &nbsp;#显示exefile类型关联的命令行，结果显示 exefile="%1" %* assoc .txt=Word.Document.8设置.txt为word类型的文档，可以看到.txt文件的图标都变了<br />
assoc .txt=txtfile恢复.txt的正确关联 ftype exefile="%1" %*恢复 exefile 的正确关联<br />
<br />
如果该关联已经被破坏，可以运行 command.com ，再输入这条命令<br />
<br />
36 pushd 和 popd切换当前目录<br />
@echo off<br />
c: &amp; cd\ &amp; md mp3&nbsp; &nbsp;&nbsp; &nbsp; #在 C:\ 建立 mp3 文件夹<br />
md d:\mp4&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#在 D:\ 建立 mp4 文件夹<br />
cd /d d:\mp4&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#更改当前目录为 d:\mp4<br />
pushd c:\mp3&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#保存当前目录，并切换当前目录为 c:\mp3<br />
popd&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#恢复当前目录为刚才保存的 d:\mp4一般用处不大，在当前目录名不确定时，会有点帮助<br />
<br />
32 subst (外部命令)映射磁盘。<br />
subst z: \\server\d&nbsp; &nbsp;&nbsp;&nbsp;#这样输入z:就可以访问\\server\d了<br />
subst z: /d&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #取消该映射<br />
subst&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #显示目前所有的映<br />
<br />
38&nbsp;&nbsp;xcopy (外部命令)文件拷贝<br />
xcopy d:\mp3 e:\mp3 /s/e/i/y复制 d:\mp3 文件夹、所有子文件夹和文件到 e:\ ，覆盖已有文件加 /i 表示如果 e:\ 没有 mp3 文件夹就自动新建一个，否则会有询问<br />
<br />
39 一些不常用的内部命令<br />
&gt;&amp; 将一个句柄的输出写入到另一个句柄的输入中<br />
&lt;&amp; 从一个句柄读取输入并将其写入到另一个句柄输出中shift 命令行传递给批处理的参数不止9个时，用以切换参数color 设置cmd窗口的显示颜色<br />
pormpt 更改命令提示符号，默认都是 盘符:\路径\&gt; ，如 c:\&gt;<br />
<br />
40 format (外部命令)格式化硬盘<br />
format c: /q/u/autotest/q表示快速格式化，/autotest表示自动格式化，不需要按 Y 确认/u表示每字节用 <br />
<br />
F6 覆盖硬盘数据，使其不可用软件恢复format c: /c格式化C盘，并检测坏道<br />
<br />
41 fdisk (外部命令)硬盘分区win2000不带<br />
<br />
该命令win98里的fdisk不支持80G以上大硬盘，winme里的支持fdisk/mbr重建硬盘分区表，一般用于清除引导区病毒、还<br />
<br />
原精灵注意使用该命令不能从硬盘启动，必须软驱或光驱启动后直接运行<br />
<br />
42 ping (外部命令)<br />
ping -l 65500 -t 192.168.1.200不停的向192.168.1.200计算机发送大小为65500byte的数据包<br />
ping -n 10 127.0.0.1&gt;nulping自己10次，可用于批处理延时10秒<br />
<br />
43 SC (外部命令)服务控制命令<br />
sc create aaa displayname= bbb start= auto binpath= "C:\WINDOWS\System32\alg.exe"创建服务，服务名称aaa，显示名称bbb，启动类型:自动可执行文件的路径"C:\WINDOWS\System32\alg.exe"<br />
sc description aaa "ccc"更改aaa的描述为ccc<br />
sc config aaa start= disabled binpath= "C:\WINDOWS\System32\svchost.exe -k netsvcs"更改aaa的启动类型:已禁用更改aaa的可执行文件的路径"C:\WINDOWS\System32\svchost.exe -k netsvcs"<br />
sc config aaa start= demand displayname= ddd更改aaa的启动类型:手动更改aaa的显示名称ddd<br />
sc start aaa启动aaa服务<br />
sc stop aaa停止aaa服务<br />
sc delete aaa删除aaa服务</div>
<img src ="http://www.blogjava.net/yruc/aggbug/173297.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2008-01-07 12:24 <a href="http://www.blogjava.net/yruc/archive/2008/01/07/173297.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IBM Developerwprks上关于SLA的文章</title><link>http://www.blogjava.net/yruc/archive/2007/09/29/149592.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Sat, 29 Sep 2007 07:43:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/09/29/149592.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/149592.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/09/29/149592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/149592.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/149592.html</trackback:ping><description><![CDATA[http://www.ibm.com/developerworks/cn/webservices/ws-slafram/<br />
http://www.ibm.com/developerworks/cn/webservices/ws-wssla/<br />
<br />
AlphaWorks Web Services Toolkit<br />
http://www.alphaworks.ibm.com/tech/webservicestoolkit<br />
<br />
Apache MUSE Project<br />
http://ws.apache.org/muse/
<img src ="http://www.blogjava.net/yruc/aggbug/149592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-09-29 15:43 <a href="http://www.blogjava.net/yruc/archive/2007/09/29/149592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CSDN上关于AXIS的文章</title><link>http://www.blogjava.net/yruc/archive/2007/09/19/146559.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Wed, 19 Sep 2007 09:56:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/09/19/146559.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/146559.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/09/19/146559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/146559.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/146559.html</trackback:ping><description><![CDATA[http://tag.csdn.net/tag/axis/1.html <br />
<br />
<span style="color: #ff0000">AXIS主页（下载地址）：<br />
http://ws.apache.org/axis/<br />
<br />
Xerces：<br />
http://xerces.apache.org/xerces-j/<br />
</span><br />
开发基于Java的Web服务入门之一：环境的配置&nbsp;<br />
http://blog.csdn.net/rackylin/archive/2005/02/01/275706.aspx<br />
<br />
开发基于Java的Web服务入门之二：应用axis发布web服务(HelloWorld)&nbsp;<br />
http://blog.csdn.net/rackylin/archive/2005/02/01/275748.aspx
<img src ="http://www.blogjava.net/yruc/aggbug/146559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-09-19 17:56 <a href="http://www.blogjava.net/yruc/archive/2007/09/19/146559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TOMCAT上Web Service开发攻略[转载]</title><link>http://www.blogjava.net/yruc/archive/2007/09/19/146557.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Wed, 19 Sep 2007 09:50:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/09/19/146557.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/146557.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/09/19/146557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/146557.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/146557.html</trackback:ping><description><![CDATA[<p style="margin: 0cm 0cm 0pt; text-indent: 27pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">随着以</span><font face="宋体"><span style="font-family: Tahoma">.NET</span><span style="font-family: 宋体">和</span><span style="font-family: Tahoma">J2EE</span><span style="font-family: 宋体">为代表的</span><span style="font-family: Tahoma">WEB</span><span style="font-family: 宋体">计算技术的兴起，</span><span style="font-family: Tahoma">WEB Service</span><span style="font-family: 宋体">已经成为越来越重要的应用，</span><span style="font-family: Tahoma">WEB Service</span><span style="font-family: 宋体">为应用系统间的集成提供了一种新型的交换方式，</span><span style="font-family: Tahoma">.NET,J2EE</span><span style="font-family: 宋体">都相继支持</span><span style="font-family: Tahoma">WEB Service</span><span style="font-family: 宋体">应用。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">笔者不想对</span><font face="宋体"><span style="font-family: Tahoma">WEB Service</span><span style="font-family: 宋体">概念和理论作过多的讨论和阐述，大家可以从下面相关的资料中进一步进行了解。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%; text-align: left" align="left"><font face="宋体"><font size="3"><span style="font-family: Tahoma">WEB</span><span style="font-family: 宋体">服务概念性体系架构</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 27pt; line-height: 150%; text-align: left" align="left"><span style="font-size: 9pt; font-family: Tahoma"><a href="http://www-900.ibm.com/developerWorks/cn/webservices/ws-wsca/part1/index.shtml"><font face="宋体" color="#190552" size="3">http://www-900.ibm.com/developerWorks/cn/webservices/ws-wsca/index.shtml</font></a></span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%; text-align: left" align="left"><span style="font-family: Tahoma"><font face="宋体"><font size="3">XML Web Service</font></font></span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 27pt; line-height: 150%"><span style="font-size: 9pt; font-family: Tahoma"><a href="http://msdn.microsoft.com/webservices/"><font face="宋体" color="#190552" size="3">http://msdn.microsoft.com/webservices/</font></a></span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 27pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">目前，</span><font face="宋体"><span style="font-family: Tahoma">Web Service</span><span style="font-family: 宋体">应用一般都采用</span><span style="font-family: Tahoma">SOAP(Simple Object Access Protocol, </span><span style="font-family: 宋体">即简单对象访问协议</span><span style="font-family: Tahoma">)</span><span style="font-family: 宋体">协议，和传统的</span><span style="font-family: Tahoma">DCOM/COM,CORBA</span><span style="font-family: 宋体">相比，</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">有以下优点：</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">首先，前者都是基于</span><font face="宋体"><span style="font-family: Tahoma">2</span><span style="font-family: 宋体">进制流的数据交换，而</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">是采用基于</span><span style="font-family: Tahoma">XML</span><span style="font-family: 宋体">的文本数据交换，因此在数据交换上更容易，更方便。调试以</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">为基础的应用程序更容易。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">其次，</span><font face="宋体"><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">采用</span><span style="font-family: Tahoma">HTTP</span><span style="font-family: 宋体">协议，并非私有的协议，所以，能够更加安全的穿越防火墙。如今，</span><span style="font-family: Tahoma">Microsoft</span><span style="font-family: 宋体">、</span><span style="font-family: Tahoma">IBM</span><span style="font-family: 宋体">、</span><span style="font-family: Tahoma">SUN</span><span style="font-family: 宋体">都在各自的产品中添加了对</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">协议的支持，所以，前者</span><span style="font-family: Tahoma">COM/DCOM</span><span style="font-family: 宋体">，</span><span style="font-family: Tahoma">CORBA</span><span style="font-family: 宋体">和</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">相比，简直不值得一提。正是</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">的出现，使得采用不同架构技术的系统的协作、交互成为可能。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font face="宋体"><font size="3"><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">是一种新型的分布式计算技术。利用</span><span style="font-family: Tahoma">SOAP</span><span style="font-family: 宋体">，同时结合其他技术，比如</span><span style="font-family: Tahoma">UDDI</span><span style="font-family: 宋体">（</span><span style="font-family: Tahoma">Universal Discovery Description, and Integration</span><span style="font-family: 宋体">）和</span><span style="font-family: Tahoma">WSDL</span><span style="font-family: 宋体">（</span><span style="font-family: Tahoma">Web Services Description Language</span><span style="font-family: 宋体">），在</span><span style="font-family: Tahoma">Web</span><span style="font-family: 宋体">服务这一概念的支持下，从而可以实现未来商业应用跨越</span><span style="font-family: Tahoma">Web</span><span style="font-family: 宋体">进行通信的方式。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">那么，接下来，让我直接进入正题，谈一谈</span><font face="宋体"><span style="font-family: Tahoma">TOMCAT</span><span style="font-family: 宋体">下，如何快速开发</span><span style="font-family: Tahoma">Web Service</span><span style="font-family: 宋体">应用。</span></font></font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font size="3"><span style="font-family: 宋体">首先，要搭建一个环境</span><font face="宋体"><span style="font-family: Tahoma">, </span><span style="font-family: 宋体">笔者搭建的环境是</span><span style="font-family: Tahoma">: Windows2000 Server(</span><span style="font-family: 宋体">中文版</span><span style="font-family: Tahoma">)+TOMCAT4</span></font></font></p>
<p><font face="宋体"><font size="3"><span style="font-size: 10.5pt; font-family: Tahoma">1 </span><span style="font-size: 10.5pt; font-family: 宋体">从</span><span style="font-size: 10.5pt; font-family: Tahoma"><a href="http://jakarta.apache.org/"><span style="color: windowtext; font-family: 'Times New Roman'">http://jakarta.apache.org/</span></a></span></font></font><font size="+0"><font size="2"><span style="font-size: 10.5pt; font-family: 宋体">下载</span><font face="宋体"><span style="font-size: 10.5pt; font-family: Tahoma">TOMCAT4,</span><span style="font-size: 10.5pt; font-family: 宋体">安装，并且配置</span><span style="font-size: 10.5pt; font-family: 宋体">好。启动</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">TOMCAT4,</span><span style="font-size: 10.5pt; font-family: 宋体">在浏览器中输入</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://localhost:8080/"><font color="#190552">http://localhost:8080</font></a></span><span style="font-size: 10.5pt; font-family: 宋体">。可以看到首页面，表示</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">TOMCAT4</span><span style="font-size: 10.5pt; font-family: 宋体">已经配置好了。</span></font></font></font></p>
<p><font size="+0"><font size="2"><font face="宋体"><span style="font-size: 10.5pt; font-family: 宋体"><img alt="" hspace="0" src="http://blog.csdn.net/Develop/ArticleImages/19/19782/CSDN_Dev_Image_2003-7-181111420.jpg" align="baseline" border="0" /></span></font></font></font></p>
<font size="+0"><font size="2"><font face="宋体"><span style="font-size: 10.5pt; font-family: 宋体">
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><span style="font-family: Tahoma">2 </span><span style="font-family: 宋体">从</span><span style="font-family: Tahoma"><a href="http://xml.apache.org/dist/axis/1_1RC1/"><span style="color: windowtext; font-family: 'Times New Roman'">http://xml.apache.org/dist/axis/1_1RC1/</span></a></span><span style="font-family: 宋体">下载</span><span style="font-family: Tahoma">AXIS</span><span style="font-family: 宋体">，解压缩到</span><span style="font-family: Tahoma">$TOMCAT_HOME/webapps/axis</span><span style="font-family: 宋体">下面去。</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体">在浏览器中运行</span><span style="font-size: 10.5pt; font-family: Tahoma"><a href="http://localhost:8080/axis/index.html">http://localhost:8080/axis/index.html</a> ,</span><span style="font-size: 10.5pt; font-family: 宋体">测试是否可以运行。</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体"><img alt="" hspace="0" src="http://blog.csdn.net/Develop/ArticleImages/19/19782/CSDN_Dev_Image_2003-7-181111422.jpg" align="baseline" border="0" /></span></p>
<span style="font-size: 10.5pt; font-family: 宋体">
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><span style="font-family: 宋体">接下来，我们开始开发一个</span><font face="Times New Roman">Web Service</font><span style="font-family: 宋体">应用。编辑一个</span><font face="Times New Roman">java</font><span style="font-family: 宋体">文件</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font face="Times New Roman">CalcService.java</font></p>
<p>
<table style="border-right: medium none; border-top: medium none; margin-left: 32.4pt; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
    <tbody>
        <tr>
            <td style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0cm; border-left: windowtext 0.5pt solid; width: 342pt; padding-top: 0cm; border-bottom: windowtext 0.5pt solid; background-color: transparent" valign="top" width="456">
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">public class CalcService {</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;public int add(int p1, int p2) {</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; return p1 + p2;</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;}</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;public int subtract(int p1, int p2) {</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; return p1 - p2;</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;}</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">}</span></p>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p><span style="font-size: 10.5pt; font-family: 宋体">复制</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">CalcService.java</span><span style="font-size: 10.5pt; font-family: 宋体">文件到</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">$TOMCAT_HOME/webapps/axis</span><span style="font-size: 10.5pt; font-family: 宋体">目录下</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">,</span><span style="font-size: 10.5pt; font-family: 宋体">改名为</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">CalcService.jws</span><span style="font-size: 10.5pt; font-family: 宋体">。在浏览器中，输入</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://localhost:8080/axis/CalcService.jws">http://localhost:8080/axis/CalcService.jws</a></span><span style="font-size: 10.5pt; font-family: 宋体">，得到提示信息如下：</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体"><img alt="" hspace="0" src="http://blog.csdn.net/Develop/ArticleImages/19/19782/CSDN_Dev_Image_2003-7-181111424.gif" align="baseline" border="0" /></span></p>
<span style="font-size: 10.5pt; font-family: 宋体">
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font face="Times New Roman">Axis</font><span style="font-family: 宋体">把</span><font face="Times New Roman">CalcService.jws</font><span style="font-family: 宋体">包装后，提供了一个</span><font face="Times New Roman">WSDL</font><span style="font-family: 宋体">的接口外露信息。可以输入</span><a href="http://localhost:8080/axis/CalcService.jws?WSDL"><font face="Times New Roman">http://localhost:8080/axis/CalcService.jws?WSDL</font></a><span style="font-family: 宋体">察看</span><font face="Times New Roman">WSDL</font><span style="font-family: 宋体">的接口信息。通过</span><font face="Times New Roman">WSDL</font><span style="font-family: 宋体">接口，我们可以遍写一个</span><font face="Times New Roman">VB</font><span style="font-family: 宋体">程序来调用。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><span style="font-family: 宋体">测试步骤如下：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font face="Times New Roman">1 </font><span style="font-family: 宋体">从</span><a href="http://www.microsoft.com/"><font face="Times New Roman" color="#190552">http://www.microsoft.com</font></a><span style="font-family: 宋体">上下载</span><font face="Times New Roman">SOAP TOOLKIT 3.0</font><span style="font-family: 宋体">，安装。</span></p>
<p><span style="font-size: 10.5pt; font-family: 'Times New Roman'">2 VB6</span><span style="font-size: 10.5pt; font-family: 宋体">中新建一个工程，添加一个</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'">FORM,FROM</span><span style="font-size: 10.5pt; font-family: 宋体">的界面如下。</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体"><img alt="" hspace="0" src="http://blog.csdn.net/Develop/ArticleImages/19/19782/CSDN_Dev_Image_2003-7-181111426.gif" align="baseline" border="0" /></span></p>
<span style="font-size: 10.5pt; font-family: 宋体">
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><font face="Times New Roman">3 </font><span style="font-family: 宋体">分别在两个按钮</span><font face="Times New Roman">cmdAdd</font><span style="font-family: 宋体">和</span><font face="Times New Roman">cmdMinus</font><span style="font-family: 宋体">中写上如下代码</span></p>
<p>
<table style="border-right: medium none; border-top: medium none; margin-left: 32.4pt; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
    <tbody>
        <tr>
            <td style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0cm; border-left: windowtext 0.5pt solid; width: 387pt; padding-top: 0cm; border-bottom: windowtext 0.5pt solid; background-color: transparent" valign="top" width="516">
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">Private Sub cmdAdd_Click()</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; '</span><span style="font-family: 宋体">测试</span><span style="font-family: Tahoma">add</span><span style="font-family: 宋体">方法</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; On Error Resume Next</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Dim SoapClient As Object</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; </span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Set SoapClient = CreateObject("MSSOAP.SoapClient30")</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Call SoapClient.MSSoapInit2(Text1.Text, "", "", "CalcService", "")</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; If Err.Number &lt;&gt; 0 Then</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox SoapClient.FaultString, vbExclamation</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; End If</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; ' Now the client can call an operation listed in the portType element</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; ' specified when calling mssoapinit().</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Text4.Text = CStr(SoapClient.Add(Val(Text2.Text), Val(Text3.Text)))</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; </span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; If Err.Number &lt;&gt; 0 Then</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox SoapClient.FaultString, vbExclamation</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; End If</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">End Sub</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">Private Sub cmdMinus_Click()</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; '</span><span style="font-family: 宋体">测试</span><span style="font-family: Tahoma">substract</span><span style="font-family: 宋体">方法</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; On Error Resume Next</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Dim SoapClient As Object</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; </span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Set SoapClient = CreateObject("MSSOAP.SoapClient30")</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Call SoapClient.MSSoapInit2(Text1.Text, "", "", "CalcService", "")</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; If Err.Number &lt;&gt; 0 Then</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox SoapClient.FaultString, vbExclamation</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; End If</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; ' Now the client can call an operation listed in the portType element</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; ' specified when calling mssoapinit().</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; Text7.Text = CStr(SoapClient.subtract(Val(Text5.Text), Val(Text6.Text)))</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; </span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; If Err.Number &lt;&gt; 0 Then</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox SoapClient.FaultString, vbExclamation</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">&nbsp;&nbsp;&nbsp; End If</span></p>
            <p style="margin: 0cm 0cm 0pt; line-height: 150%"><span style="font-family: Tahoma">End Sub</span></p>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><span style="font-family: 宋体">其中需要注意的是，</span><font face="Times New Roman">MSSoapInit2</font><span style="font-family: 宋体">方法简单地说明如下：</span></p>
<p>
<table style="border-right: medium none; border-top: medium none; margin-left: 32.4pt; border-left: medium none; border-bottom: medium none; border-collapse: collapse" cellspacing="0" cellpadding="0" border="1">
    <tbody>
        <tr>
            <td style="border-right: windowtext 0.5pt solid; padding-right: 5.4pt; border-top: windowtext 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0cm; border-left: windowtext 0.5pt solid; width: 387pt; padding-top: 0cm; border-bottom: windowtext 0.5pt solid; background-color: transparent" valign="top" width="516">
            <pre><span style="font-size: 10.5pt"><font face="黑体">HRESULT MSSoapInit2(</font></span></pre>
            <pre><span style="font-size: 10.5pt"><font face="黑体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [in] VARIANT par_WSDLFile, </font></span></pre>
            <pre><span style="font-size: 10.5pt"><font face="黑体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[in] VARIANT par_WSMLFile, </font></span></pre>
            <pre><span style="font-size: 10.5pt"><font face="黑体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[in] BSTR par_ServiceName, </font></span></pre>
            <pre><span style="font-size: 10.5pt"><font face="黑体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[in] BSTR par_Port, </font></span></pre>
            <pre><font face="黑体"><span style="font-size: 10.5pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[in] BSTR par_Namespace);</span></font></pre>
            <pre><font size="2"><font face="黑体">&nbsp;</font></font></pre>
            <pre><font face="黑体" size="2">par_WSDLFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WSDL文件的位置，本例中为</font></pre>
            <pre style="text-indent: 150pt"><font face="黑体" size="2">http://localhost:8080/axis/CalcService.jws?wsdl</font></pre>
            <pre><font face="黑体" size="2">par_WSMLFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本例中为空</font></pre>
            <pre><font face="黑体"><span style="font-size: 10.5pt">par_ServiceName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><font size="2">本例中为空</font></font></pre>
            <pre><font face="黑体"><span style="font-size: 10.5pt">par_Port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10.5pt">服务端口号，可以从wsdl文件中找到。</span></font></pre>
            <pre><font face="黑体"><span style="font-size: 10.5pt">par_Namespace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><font size="2">本例中为空</font></font></pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p style="margin: 0cm 0cm 0pt; text-indent: 23.65pt; line-height: 150%"><span style="font-family: 宋体">关于</span><font face="Times New Roman">Microsoft SOAP TOOLKIT 3.0</font><span style="font-family: 宋体">的详细说明，我会以后，专门写文章介绍。</span></p>
<p><span style="font-size: 10.5pt; font-family: 'Times New Roman'">4 </span><span style="font-size: 10.5pt; font-family: 宋体">运行，并且测试。</span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体"><img alt="" hspace="0" src="http://blog.csdn.net/Develop/ArticleImages/19/19782/CSDN_Dev_Image_2003-7-181111428.gif" align="baseline" border="0" /></span></p>
<p><span style="font-size: 10.5pt; font-family: 宋体"><span style="font-size: 10.5pt; font-family: 宋体">总结，应用Web Service技术，我们已经看到了，用VB编写的程序一样可以享用JAVA技术，当然也可以享用.NET技术，当然java编写的应用一样可以享用VB6或.NET开发的WebService。这项技术的应用必将给信息系统的结构模式带来全新的改变。</span></span></span></span></span></span></font></font></font></p>
<img src ="http://www.blogjava.net/yruc/aggbug/146557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-09-19 17:50 <a href="http://www.blogjava.net/yruc/archive/2007/09/19/146557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何使用java.util.regex包</title><link>http://www.blogjava.net/yruc/archive/2007/09/06/143087.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Thu, 06 Sep 2007 02:14:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/09/06/143087.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/143087.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/09/06/143087.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/143087.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/143087.html</trackback:ping><description><![CDATA[在Sun的Java JDK 1.40版本中，Java自带了支持正则表达式的包，本文就抛砖引玉地介绍了如何使用java.util.regex包。
<p>　　可粗略估计一下，除了偶尔用Linux的外，其他Linu x用户都会遇到正则表达式。正则表达式是个极端强大工具，而且在字符串模式-匹配和字符串模式-替换方面富有弹性。在Unix世界里，正则表达式几乎没有什么限制，可肯定的是，它应用非常之广泛。</p>
<p>　　正则表达式的引擎已被许多普通的Unix工具所实现，包括grep，awk，vi和Emacs等。此外，许多使用比较广泛的脚本语言也支持正则表达式，比如Python，Tcl，JavaScript，以及最著名的Perl。</p>
<p>　　我很早以前就是个Perl方面的黑客，如果你和我一样话，你也会非常依赖你手边的这些强大的text-munging工具。近几年来，像其他程序开发者一样，我也越来越关注Java的开发。</p>
<p>　　Java作为一种开发语言，有许多值得推荐的地方，但是它一直以来没有自带对正则表达式的支持。直到最近，借助于第三方的类库，Java开始支持正则表达式，但这些第三方的类库都不一致、兼容性差，而且维护代码起来很糟糕。这个缺点，对我选择Java作为首要的开发工具来说，一直是个巨大的顾虑之处。</p>
<p>　　你可以想象，当我知道Sun的Java JDK 1.40版本包含了java.util.regex(一个完全开放、自带的正则表达式包)时，是多么的高兴!很搞笑的说，我花好些时间去挖掘这个被隐藏起来的宝石。我非常惊奇的是，Java这样的一个很大改进(自带了java.util.regex包)为什么不多公开一点呢?!</p>
<p>　　最近，Java双脚都跳进了正则表达式的世界。java.util.regex包在支持正则表达也有它的过人之处，另外Java也提供详细的相关说明文档。使得朦朦胧胧的regex神秘景象也慢慢被拨开。有一些正则表达式的构成(可能最显著的是，在于糅合了字符类库)在Perl都找不到。</p>
<p>　　在regex包中，包括了两个类，Pattern(模式类)和Matcher(匹配器类)。Pattern类是用来表达和陈述所要搜索模式的对象，Matcher类是真正影响搜索的对象。另加一个新的例外类，PatternSyntaxException，当遇到不合法的搜索模式时，会抛出例外。</p>
<p>　　即使对正则表达式很熟悉，你会发现，通过java使用正则表达式也相当简单。要说明的一点是，对那些被Perl的单行匹配所宠坏的Perl狂热爱好者来说，在使用java的regex包进行替换操作时，会比他们所以前常用的方法费事些。</p>
<p>　　本文的局限之处，它不是一篇正则表达式用法的完全教程。如果读者要对正则表达进一步了解的话，推荐阅读Jeffrey Frieldl的Mastering Regular Expressions，该书由O&#8217;Reilly出版社出版。我下面就举一些例子来教读者如何使用正则表达式，以及如何更简单地去使用它。</p>
<p>　　设计一个简单的表达式来匹配任何电话号码数字可能是比较复杂的事情，原因在于电话号码格式有很多种情况。所有必须选择一个比较有效的模式。比如:(212) 555-1212， 212-555-1212和212 555 1212，某些人会认为它们都是等价的。</p>
<p>　　首先让我们构成一个正则表达式。为简单起见，先构成一个正则表达式来识别下面格式的电话号码数字:(nnn)nnn-nnnn。</p>
<p>　　第一步，创建一个pattern对象来匹配上面的子字符串。一旦程序运行后，如果需要的话，可以让这个对象一般化。匹配上面格式的正则表达可以这样构成:(\d{3})\s\d{3}-\d{4}，其中\d单字符类型用来匹配从0到9的任何数字，另外{3}重复符号，是个简便的记号，用来表示有3个连续的数字位，也等效于(\d\d\d)。\s也另外一个比较有用的单字符类型，用来匹配空格，比如Space键，tab键和换行符。</p>
<p>　　是不是很简单?但是，如果把这个正则表达式的模式用在java程序中，还要做两件事。对java的解释器来说，在反斜线字符(\)前的字符有特殊的含义。在java中，与regex有关的包，并不都能理解和识别反斜线字符(\)，尽管可以试试看。但为避免这一点，即为了让反斜线字符(\)在模式对象中被完全地传递，应该用双反斜线字符(\)。此外圆括号在正则表达中两层含义，如果想让它解释为字面上意思(即圆括号)，也需要在它前面用双反斜线字符(\)。也就是像下面的一样:</p>
<p>　　\\(\\d{3}\\)\\s\\d{3}-\\d{4}</p>
<p>　　现在介绍怎样在java代码中实现刚才所讲的正则表达式。要记住的事，在用正则表达式的包时，在你所定义的类前需要包含该包，也就是这样的一行:</p>
<p>　　import java.util.regex.*;</p>
<p>　　下面的一段代码实现的功能是，从一个文本文件逐行读入，并逐行搜索电话号码数字，一旦找到所匹配的，然后输出在控制台。</p>
<p>　　BufferedReader in;</p>
<p>　　Pattern pattern = Pattern.compile("\\(\\d{3}\\)\\s\\d{3}-\\d{4}");</p>
<p>　　in = new BufferedReader(new FileReader("phone"));</p>
<p>　　String s;</p>
<p>　　while ((s = in.readLine()) != null)</p>
<p>　　{</p>
<p>　　Matcher matcher = pattern.matcher(s);</p>
<p>　　if (matcher.find())</p>
<p>　　{</p>
<p>　　System.out.println(matcher.group());</p>
<p>　　}</p>
<p>　　}</p>
<p>　　in.close();</p>
<p>　　对那些熟悉用Python或Javascript来实现正则表达式的人来说，这段代码很平常。在Python和Javascript这些语言中，或者其他的语言，这些正则表达式一旦明确地编译过后，你想用到哪里都可以。与Perl的单步匹配相比，看起来多多做了些工作，但这并不很费事。</p>
<p>　　find()方法，就像你所想象的，用来搜索与正则表达式相匹配的任何目标字符串，group()方法，用来返回包含了所匹配文本的字符串。应注意的是，上面的代码，仅用在每行只能含有一个匹配的电话号码数字字符串时。可以肯定的说，java的正则表达式包能用在一行含有多个匹配目标时的搜索。本文的原意在于举一些简单的例子来激起读者进一步去学习java自带的正则表达式包，所以对此就没有进行深入的探讨。</p>
<p>　　这相当漂亮吧! 但是很遗憾的是，这仅是个电话号码匹配器。很明显，还有两点可以改进。如果在电话号码的开头，即区位号和本地号码之间可能会有空格。我们也可匹配这些情况，则通过在正则表达式中加入\s?来实现，其中?元字符表示在模式可能有0或1个空格符。</p>
<p>　　第二点是，在本地号码位的前三位和后四位数字间有可能是空格符，而不是连字号，更有胜者，或根本就没有分隔符，就是7位数字连在一起。对这几种情况，我们可以用(-|)?来解决。这个结构的正则表达式就是转换器，它能匹配上面所说的几种情况。在()能含有管道符|时，它能匹配是否含有空格符或连字符，而尾部的?元字符表示是否根本没有分隔符的情况。</p>
<p>　　最后，区位号也可能没有包含在圆括号内，对此可以简单地在圆括号后附上?元字符，但这不是一个很好的解决方法。因为它也包含了不配对的圆括号，比如"(555" 或 "555)"。相反，我们可以通过另一种转换器来强迫让电话号码是否带有有圆括号:(\(\d{3}\)|\d{3})。如果我们把上面代码中的正则表达式用这些改进后的来替换的话，上面的代码就成了一个非常有用的电话号码数字匹配器:</p>
<p>　　Pattern pattern =</p>
<p>　　Pattern.compile("(\\(\\d{3}\\)|\\d{3})\\s?\\d{3}(-|)?\\d{4}");</p>
<p>　　可以确定的是，你可以自己试着进一步改进上面的代码。</p>
<p>　　现在看看第二个例子，它是从Friedl的中改编过来的。其功能是用来检查文本文件中是否有重复的单词，这在印刷排版中会经常遇到，同样也是个语法检查器的问题。</p>
<p>　　匹配单词，像其他的一样，也可以通过好几种的正则表达式来完成。可能最直接的是\b\w+\b，其优点在于只需用少量的regex元字符。其中\w元字符用来匹配从字母a到u的任何字符。+元字符表示匹配匹配一次或多次字符，\b元字符是用来说明匹配单词的边界，它可以是空格或任何一种不同的标点符号(包括逗号，句号等)。</p>
<p>　　现在，我们怎样来检查一个给定的单词是否被重复了三次?为完成这个任务，需充分利用正则表达式中的所熟知的向后扫描。如前面提到的，圆括号在正则表达式中有几种不同的用法，一个就是能提供组合类型，组合类型用来保存所匹配的结果或部分匹配的结果(以便后面能用到)，即使遇到有相同的模式。在同样的正则表达中，可能(也通常期望)不止有一个组合类型。在第n个组合类型中匹配结果可以通过向后扫描来获取到。向后扫描使得搜索重复的单词非常简单:\b(\w+)\s+\1\b。</p>
<p>　　圆括号形成了一个组合类型，在这个正则表示中它是第一组合类型(也是仅有的一个)。向后扫描\1，指的是任何被\w+所匹配的单词。我们的正则表达式因此能匹配这样的单词，它有一个或多个空格符，后面还跟有一个与此相同的单词。注意的是，尾部的定位类型(\b)必不可少，它可以防止发生错误。如果我们想匹配"Paris in the the spring"，而不是匹配"Java's regex package is the theme of this article"。根据java现在的格式，则上面的正则表达式就是:Pattern pattern =Pattern.compile("\\b(\\w+)\\s+\\1\\b");</p>
<p>　　最后进一步的修改是让我们的匹配器对大小写敏感。比如，下面的情况:"The the theme of this article is the Java's regex package."，这一点在regex中能非常简单地实现，即通过使用在Pattern类中预定义的静态标志CASE_INSENSITIVE :</p>
<p>　　Pattern pattern =Pattern.compile("\\b(\\w+)\\s+\\1\\b",</p>
<p>　　Pattern.CASE_INSENSITIVE);</p>
<p>　　有关正则表达式的话题是非常丰富，而且复杂的，用Java来实现也非常广泛，则需要对regex包进行的彻底研究，我们在这里所讲的只是冰山一角。即使你对正则表达式比较陌生，使用regex包后会很快发现它强大功能和可伸缩性。如果你是个来自Perl或其他语言王国的老练的正则表达式的黑客，使用过regex包后，你将会安心地投入到java的世界，而放弃其他的工具，并把java的regex包看成是手边必备的利器。</p>
<img src ="http://www.blogjava.net/yruc/aggbug/143087.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-09-06 10:14 <a href="http://www.blogjava.net/yruc/archive/2007/09/06/143087.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python完全新手教程</title><link>http://www.blogjava.net/yruc/archive/2007/06/15/124497.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Fri, 15 Jun 2007 06:42:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/06/15/124497.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/124497.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/06/15/124497.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/124497.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/124497.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Python完全新手教程 作者：taowen, billriceLesson 1 准备好学习Python的环境下载的地址是：www.python.org为了大家的方便，我在校内作了copy：http://10.1.204.2/tool/compiler&amp;IDE/Python-2.3.2-1.exelinux版本的我就不说了，因为如果你能够使用linux并安装好说明你可以一切自己搞定的。...&nbsp;&nbsp;<a href='http://www.blogjava.net/yruc/archive/2007/06/15/124497.html'>阅读全文</a><img src ="http://www.blogjava.net/yruc/aggbug/124497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-06-15 14:42 <a href="http://www.blogjava.net/yruc/archive/2007/06/15/124497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Telnet中ftp的基本命令</title><link>http://www.blogjava.net/yruc/archive/2007/05/28/120504.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Mon, 28 May 2007 08:44:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/05/28/120504.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/120504.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/05/28/120504.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/120504.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/120504.html</trackback:ping><description><![CDATA[FTP:文件传输协议。先说说他的功能吧，主要就是从运行FTP服务器的计算机传输文件。可以交互使用。这里要注意，只有安装了tcp/ip协议的机器才能使用ftp命令。 <br>命令格式：ftp [-v][-d][-i][-n][-g][-s:filename][-a][-w:windowsize][computer] <br><br>说说他们的含义吧。 <br>-v 不显示远程服务器响应 <br>-n 禁止第一次连接的时候自动登陆 <br>-i 在多个文件传输期间关闭交互提示 <br>-d 允许调试、显示客户机和服务器之间传递的全部ftp命令 <br>-g 不允许使用文件名通配符，文件名通配符的意思是说允许在本地文件以及路径名中使用通配字符 <br>-s:filename 指定包含ftp命令的文本文件。在ftp命令启动后将自动运行这些命令。在加的参数里不能有空格。 <br>-a 绑定数据连接时，使用任何的本地端口 <br>-w:windowsize 忽略默认的4096传输缓冲区 <br>computer 指定要连接的远程计算机的ip地址 <br><br><br>呵呵，理解了上面的，就说说一些具体的命令，我个人觉得虽然现在工具用起来很方便了，但懂这些命令在很多地方还是很有用的，就像现在nt下的命令提示符 <br>1） ? <br>说明：显示ftp命令的说明。后面可以加参数，是加需要解释的命令名，不加则显示包含所有命令列表。 <br><br>2） append <br>说明：使用当前文件类型设置，将本地文件附加到远程计算机中。大概格式是 <br>append local-file [remote-file] 其中local-file是说指定要添加的本地文件。 <br>remote-file是说指定要将local-file附加到远程计算机文件，要是省了这个，则是使用本地文件名做远程文件名。 <br><br>3)ascii <br>说明:默认情况下，将文件传输类型设置为ASCII <br><br>4)bell <br>说明：响玲开关，意思是文件传输完成后是否有玲声提醒。默认是关闭的。 <br><br>5)binary <br>说明：将文件传输类型设置为二进制。 <br><br>6)bye <br>说明:结束和远程计算机的ftp会话，也就是安全断开，退出ftp. <br><br>7)cd <br>说明：更改远程计算机上的工作目录。如cd data 其中data是要进入的远程计算机的目录。 <br><br>8)close <br>说明:结束与远程服务器的ftp会话，并返回命令解释程序。 <br><br>9)dir <br>说明:显示远程的文件以及子目录列表。如dir data local-file <br>其中data是指定要查看列表的目录，没指定的话就是当前目录。local-file是指定要保存列表的本地文件，不指定的话就在屏幕输出。 <br><br>10)debug <br>说明：调试开关，打开的时候打印每个发送到远程计算机的命令，命令前有——&gt; <br>默认情况是关闭的。 <br><br>11)disconnnect <br>说明：与远程计算机断开连接，但还保持着ftp命令提示符。 <br><br>12)get <br>说明：使用当前文件传输类型，把远程的文件拷贝到本地计算机上。 <br>如get remote-file local-file <br>remote-file是指定要复制的文件，local-file是指定本地计算机上的文件名， <br>没有指定的话则个remote-file同名。 <br><br>13)glob <br>说明：文件名通配开关 <br><br>14)hash <br>说明：转换每个传输数据快的散列标记打印(#).数据快的大小是2048字节。默认情况下是关闭的， <br><br>15)help <br>说明：显示ftp命令的解释，如help commmand 其中command就是你要解释的命令，如果不加command这个参数的话就会显示所有命令的列表 <br><br>16)! <br>说明:这个命令差点忘记了功能是在本地计算机上运行指定命令。如! command 其中command就是你要运行的命令，如果不加command这个参数的话，则显示本地命令提示， 这时你输入exit命令就能返回到ftp了。 <br><br>17)lcd <br>说明:更改本地计算机的本地目录,在默认的时候是启动ftp的目录.这个不要觉得没用啊，在你使用ftp的时候为了传递文件不是常改变本地和远程计算机的目录吗? <br>如lcd [directory] 其中[directory]是指定要进入的本地计算机的目录,如果你不加这个参数,就会显示出本地计算机的工作目录. <br><br>18)literal <br>说明:向远程ftp服务器发送协商参数,报告. <br>如lireral argument [...] 其中argument是指定要发送给远程服务器的协商参数。 <br><br>19)ls <br>说明:显示远程目录的文件和字目录. <br>如ls remote-directory local-file <br>其中remote-directory是指要查看的列表的目录,不指定的话显示的是当前工作目录。local-file是指定要保存列表的本地文件.不指定的话是在屏幕上输出. <br><br>20)mdelete <br>说明:删除远程计算机上的文件.如mdelete remote-file ... <br>remote-file肯定是要删的文件啊，可以删除多个. <br><br>21)mdir <br>说明:显示远程目录的文件和子目录列表,他允许指定多个文件. <br>如mdir remote-file ... local-file <br>参数我想大家应该明白什么意思吧?不明白就看看前面的类似命令吧. <br><br>22)mget <br>说明:使用当前文件传输类型将多个远程文件复制到本地计算机. <br>如mget remote-files ... <br>其实remote-files可以指定多个，他就是指定要复制到本地计算机的远程文件. <br><br>23)mkdir <br>说明:创建远程目录. <br>如mkdir directory 这个命令和nt下的命令提示符中的md directory一样，不多说了. <br><br>24)mls <br>说明:显示远程目录的文件和目录简表 <br>如mls remote-file ... local-file <br>其中remote-file这个参数是必须要加的，&#8217;&#8217;-&#8217;&#8217;是使用远程计算机的当前工作目录. <br><br>25)mput <br>说明:使用当前文件传输类型,将本地文件复制到远程计算机. <br>如mput local-files ... <br><br>26)open <br>说明:连接到指定ftp服务器上， <br>如open computer port 其中computer一般是远程计算机的ip地址,port不用说就是指定端口了。 <br><br>27)prompt <br>说明:转换提示,在多个文件传输的时候,ftp提示可以有选择的检索或保存文件，如果关闭提示,则mget和mput命令传输所有文件,在默认情况下是打开的. <br><br>28)put <br>说明:使用当前文件传输类型将本地文件复制到远程计算机中， <br>如put local-file remote-file <br>其中local-file是指定要复制的本地文件， <br>remote-file是指定要复制的远程计算机上的文件名，不指定的话是和本地计算机上的文件名同名. <br><br>29)pwd <br>说明:显示远程呢感计算机上的当前目录. <br><br>30)quit <br>说明:结束与远程计算机的ftp会话,并退出ftp. <br><br>31)quote <br>说明:向远程ftp服务器发送协议,报告.期待ftp单码应答,这个命令的功能和literal相同. <br><br>32)recv <br>说明:使用当前文件传输类型将远程文件复制到本地计算机,他与get命令作用相同。 <br><br>33)remotehelp <br>说明:显示远程命令的帮助.这个命令的用法和help,!一样可以参考他的用法. <br><br>34)rename <br>说明:更改远程计算机上的文件名。 <br>这个命令和nt的命令提示符的ren一样，如rename filename newfilename <br><br>35)rmdir <br>说明:删除远程目录. <br>这个命令和nt的命令提示符的rm一样，如rmdir directory <br><br>36)send <br>说明:使用当前文件传输类型将本地文件复制到远程计算机.send和put命令的功能一样。 <br>如send local-file remote-file <br><br>37)status <br>说明:显示ftp连接和转换的当前状态 <br><br>38)trace <br>说明:转换报文跟踪,运行ftp的命令时,trace将显示没个报文的理由。 <br><br>39)type <br>说明:设置或显示文件传输类型. <br>如type [type-name] <br>其中type-name 的意思是文件传输的类型，默认是ASCII,没加这个参数就是显示当前的传输类型. <br><br>40)user <br>说明:指定连接到远程计算机的用户. <br>如user user-name [passwd] [account] <br>其中user-name不用说都是用来登陆计算机的用户名了， <br>passwd是指定user-name的密码,不指定的话ftp会提示输入密码。 <br>account是指定用来登陆计算机的帐号,如不指定,ftp会提示输入帐号. <br><br>41)verbose <br>说明:转换冗余模式。这里如果打开,会显示所有ftp响应,文件传输结束的时候会显示传输的效率和统计信息,默认的情况是打开的. <br><br>呵呵，命令就介绍这些了，可以自己熟悉一下,其实现在ftp的软件很多,很方便，但你说这些命令没用也是不可能的，就像windows下一样还保留着命令提示符._ 特别有些时候ftp软件很多地方做不到的，.? 什么地方。 <br>打个比方，我看过一种觅名ftp用户得到admin的入侵列子,就的用到他.呵呵，这里不多说了,就写到这里了。</ca>
<img src ="http://www.blogjava.net/yruc/aggbug/120504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-05-28 16:44 <a href="http://www.blogjava.net/yruc/archive/2007/05/28/120504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDBC2.0 batch updates </title><link>http://www.blogjava.net/yruc/archive/2007/04/28/114274.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Sat, 28 Apr 2007 02:54:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/04/28/114274.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/114274.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/04/28/114274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/114274.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/114274.html</trackback:ping><description><![CDATA[<div style="MARGIN-TOP: 1px; MARGIN-LEFT: 15px">
<h2>JDBC2.0 batch updates </h2>
</div>
<div style="MARGIN-TOP: 5px; MARGIN-LEFT: 15px"><strong>关键字:</strong> &nbsp; JDBC 批量更新&nbsp;&nbsp;&nbsp;&nbsp; </div>
<div style="MARGIN-TOP: 10px; MARGIN-LEFT: 15px; OVERFLOW: auto">
<table width="100%">
    <tbody>
        <tr>
            <td>
            <pre>boolean isSupportBatchUpdates(Connection conn)<br>&nbsp;&nbsp; DatabaseMetaData dbm = con.getMetaData();<br>&nbsp;&nbsp; if(dbm.supportBatchUpdates())<br>&nbsp;&nbsp;&nbsp;&nbsp; return true;<br>&nbsp;&nbsp; //notice: catch SQLException,AbstractMethodError<br>&nbsp;&nbsp; return false;</pre>
            <pre>int[] batchUpdate(String[] sql)<br>&nbsp;&nbsp; //make sure sql is not null!!!<br>&nbsp;&nbsp; int res = new int[sql.length];<br>&nbsp;&nbsp; if(isSupportBatchUpdates(conn)){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0;i<sql><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stmt.addBatch(sql[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res = stmt.executeBatch();<br>&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0 ;i<sql><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!stmt.execute(sql[i]))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res[i] = stmt.getUpdateCount();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else throw new ....<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; return res;</pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<img src ="http://www.blogjava.net/yruc/aggbug/114274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-04-28 10:54 <a href="http://www.blogjava.net/yruc/archive/2007/04/28/114274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WebSphere的默认管理员和口令</title><link>http://www.blogjava.net/yruc/archive/2007/03/27/106594.html</link><dc:creator>yangrui</dc:creator><author>yangrui</author><pubDate>Tue, 27 Mar 2007 02:01:00 GMT</pubDate><guid>http://www.blogjava.net/yruc/archive/2007/03/27/106594.html</guid><wfw:comment>http://www.blogjava.net/yruc/comments/106594.html</wfw:comment><comments>http://www.blogjava.net/yruc/archive/2007/03/27/106594.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yruc/comments/commentRss/106594.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yruc/services/trackbacks/106594.html</trackback:ping><description><![CDATA[username: system<br />password: manager<img src ="http://www.blogjava.net/yruc/aggbug/106594.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yruc/" target="_blank">yangrui</a> 2007-03-27 10:01 <a href="http://www.blogjava.net/yruc/archive/2007/03/27/106594.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>