??xml version="1.0" encoding="utf-8" standalone="yes"?>91美女视频在线,羞羞色午夜精品一区二区三区,亚洲一卡久久http://www.aygfsteel.com/nbtymm/category/12091.html</br><a ><b><font color=red>共有<script src=http://fastonlineusers.com/online.php?d=bluedavy.blogjava.net></script>人在同时阅读此Blog</font></b></a>zh-cnFri, 02 Mar 2007 02:03:33 GMTFri, 02 Mar 2007 02:03:33 GMT60Eclipse快速上手指南之使用Ant http://www.aygfsteel.com/nbtymm/archive/2006/08/14/63398.htmlnbtnbtMon, 14 Aug 2006 01:34:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/08/14/63398.htmlhttp://www.aygfsteel.com/nbtymm/comments/63398.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/08/14/63398.html#Feedback1http://www.aygfsteel.com/nbtymm/comments/commentRss/63398.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/63398.html
Ant是Javaq_下非常棒的批处理命o(h)执行E序Q能自动完成~译Q测试,打包Q部|等{一pdd?

  Ant是Javaq_下非常棒的批处理命o(h)执行E序Q能非常方便地自动完成编译,试Q打包,部v{等一pddQ大大提高开发效率。如果你现在q没有开始用AntQ那p赶快开始学?fn)用,使自q开发水q上一个新台阶?/p>

  Eclipse 中已l集成了(jin)AntQ我们可以直接在Eclipse中运行Ant?/p>

  以前面徏立的Hello工程ZQ创Z下目录结构:(x)

  新徏一个build.xmlQ放在工E根目录下。build.xml定义?jin)Ant要执行的批处理命令。虽然Ant也可以用其它文件名Q但是遵循标准能更开发更规范Q同时易于与别h交流?/p>

  通常Qsrc存放Java源文Ӟclasses存放~译后的class文gQlib存放~译和运行用到的所有jar文gQweb存放JSP{web文gQdist存放打包后的jar文gQdoc存放API文?/p>

  然后在根目录下创建build.xml文gQ输入以下内容:(x)

<xml version="1.0"?>
<project name="Hello world" default="doc">

<-- properies -->
<property name="src.dir" value="src" />
<property name="report.dir" value="report" />
<property name="classes.dir" value="classes" />
<property name="lib.dir" value="lib" />
<property name="dist.dir" value="dist" />
<property name="doc.dir" value="doc"/>

<-- 定义classpath -->
<path id="master-classpath">
<fileset file="${lib.dir}/*.jar" />
<pathelement path="${classes.dir}"/>
<path>

<-- 初始化Q?-->
<target name="init">
<target>

<-- ~译 -->
<target name="compile" depends="init" description="compile the source files">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.4">
<classpath refid="master-classpath"/>
<javac>
<target>

<-- 试 -->
<target name="test" depends="compile" description="run junit test">
<mkdir dir="${report.dir}"/>
<junit printsummary="on"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath" />
<ormatter type="plain"/>
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/*Test.*"/>
<fileset>
<batchtest>
<junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
<fail/>
<target/>

<-- 打包成jar -->
<target name="pack" depends="test" description="make .jar file">
<mkdir dir="${dist.dir}" />
<jar destfile="${dist.dir}/hello.jar" basedir="${classes.dir}">
<xclude name="**/*Test.*" />
<xclude name="**/Test*.*" />
<jar/>
<targe/t>

<-- 输出api文 -->
<target name="doc" depends="pack" description="create api doc">
<mkdir dir="${doc.dir}" />
<javadoc destdir="${doc.dir}"
author="true"
version="true"
use="true"
windowtitle="Test API">
<packageset dir="${src.dir}" defaultexcludes="yes">
<include name="example/**" />
<packageset/>
<doctitle>[CDATA[<1>ello, test<h1>]>doctitle>
<dottom>[CDATA[<>ll Rights Reserved.<i>]>bottom>
<tag name="todo" scope="all" description="To do:" />
<javadoc/>
<target/>
<project/>

  以上xml依次定义?jin)initQ初始化Q,compileQ编译)(j)QtestQ测试)(j)QdocQ生成文)(j)QpackQ打包)(j)dQ可以作为模ѝ?/p>

  选中Hello工程Q然后选择“Project”,“Properties”,“Builders”,“New…”,选择“Ant Build”:(x)

  填入NameQAnt_BuilderQBuildfileQbuild.xmlQBase DirectoryQ?{workspace_loc:/Hello}Q按“Browse Workspace”选择工程根目录)(j)Q由于用C(jin)junit.jar包,搜烦(ch)Eclipse目录Q找到junit.jarQ把它复制到Hello/lib目录下,q添加到Ant的Classpath中:(x)

  然后在Builder面板中钩上Ant_BuildQ去掉Java BuilderQ?/p>

  再次~译Q即可在控制台看到Ant的输出:(x)

Buildfile: F:\eclipse-projects\Hello\build.xml

init:

compile:
[mkdir] Created dir: F:\eclipse-projects\Hello\classes
[javac] Compiling 2 source files to F:\eclipse-projects\Hello\classes

test:
[mkdir] Created dir: F:\eclipse-projects\Hello\report
[junit] Running example.HelloTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.02 sec

pack:
[mkdir] Created dir: F:\eclipse-projects\Hello\dist
[jar] Building jar: F:\eclipse-projects\Hello\dist\hello.jar

doc:
[mkdir] Created dir: F:\eclipse-projects\Hello\doc
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source files for package example...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.4.2_04
[javadoc] Building tree for all the packages and classes...
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...
[javadoc] Generating F:\eclipse-projects\Hello\doc\stylesheet.css...
[javadoc] Note: Custom tags that could override future standard tags: @todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
[javadoc] Note: Custom tags that were not seen: @todo
BUILD SUCCESSFUL
Total time: 11 seconds

  Ant依次执行初始化,~译Q测试,打包Q生成API文一pddQ极大地提高?jin)开发效率。将来开发J2EE目Ӟq可加入部v{Q务。ƈ且,即q?jin)Eclipse环境Q只要正安装了(jin)AntQ配|好环境变量ANT_HOME=<nt解压目录>Path=?%ANT_HOME%\binQ在命o(h)行提C符下切换到Hello目录Q简单地键入ant卛_?/p>

nbt 2006-08-14 09:34 发表评论
]]>
IIS 集成 Tomcat http://www.aygfsteel.com/nbtymm/archive/2006/07/06/56887.htmlnbtnbtThu, 06 Jul 2006 00:46:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/07/06/56887.htmlhttp://www.aygfsteel.com/nbtymm/comments/56887.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/07/06/56887.html#Feedback0http://www.aygfsteel.com/nbtymm/comments/commentRss/56887.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/56887.html阅读全文

nbt 2006-07-06 08:46 发表评论
]]>
ZJ2EE轻量U架构的多层应用的研I?(转蝲自http://www.aygfsteel.com/caoqingsong/archive/2006/06/16/53158.html)http://www.aygfsteel.com/nbtymm/archive/2006/06/16/53191.htmlnbtnbtFri, 16 Jun 2006 03:20:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/06/16/53191.htmlhttp://www.aygfsteel.com/nbtymm/comments/53191.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/06/16/53191.html#Feedback0http://www.aygfsteel.com/nbtymm/comments/commentRss/53191.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/53191.html阅读全文

nbt 2006-06-16 11:20 发表评论
]]>
ant+cactus+tomcat5.5容器内单元测试简明手?/title><link>http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52167.html</link><dc:creator>nbt</dc:creator><author>nbt</author><pubDate>Mon, 12 Jun 2006 03:48:00 GMT</pubDate><guid>http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52167.html</guid><wfw:comment>http://www.aygfsteel.com/nbtymm/comments/52167.html</wfw:comment><comments>http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52167.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/nbtymm/comments/commentRss/52167.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/nbtymm/services/trackbacks/52167.html</trackback:ping><description><![CDATA[ <div id="wmqeeuq" class="center"> <h4>摘要:</h4>折腾?jin)一个星期,l于搞定ant+cactus+tomcat5.5容器内单元测试,为感谢cleverpig斑竹的热?j)回_(d)牚w发于matrix apache版?</div> <div id="wmqeeuq" class="right"> <div id="wmqeeuq" class="help"> <h4>文章工具</h4> <a >收藏</a> <br /> <a >投票评分</a> <br /> <a >发表评论</a> <br /> <a onclick="copyLink('ant+cactus+tomcat5.5容器内单元测试简明手?);" >复制链接</a> <br /> </div> </div> <!-- end of summary line --> <div id="wmqeeuq" class="overflow" id="text">折腾?jin)一个星期,l于搞定ant+cactus+tomcat5.5容器内单元测试,为感谢cleverpig斑竹(<a target="_new">http://blog.matrix.org.cn/page/cleverpig</a>)的热?j)回_(d)牚w发于matrix apache版。关于ant的用,h索ant的用手册,|上大把中文的?br /><br /><span style="COLOR: blue">一、下载ƈ解压~cactus</span><br />下蝲地址?a target="_new">http://apache.freelamp.com/jakarta/cactus/binaries/jakarta-cactus-12-1.7.1.zip</a>。将cactus的lib目录下的cactus-ant-1.7.1.jar复制到ant的lib目录?br /><br /><br /><span style="COLOR: blue">二、配|cactus</span><br />cactus的配|很单,新徏一个cactus.properties文gQƈ把它攑֜ant脚本中的cactusd的classpath下,文g中包括如下内?br /><pre class="overflow">cactus.sysproperties=cactus.contextURL<br />#cactus-sample-servlet-cactified是你的试应用所在\径,8080是端口号<br />cactus.contextURL = http://localhost:8080/cactus-sample-servlet-cactified<br />cactus.servletRedirectorName = ServletRedirector<br />cactus.jspRedirectorName = JspRedirector<br />cactus.filterRedirectorName = FilterRedirector </pre><br />具体的做法结合ant脚本再进一步解释?br /><br /><span style="COLOR: blue">三、运行ant脚本</span><br />  ant脚本主要执行以下d<br /><br /><span style="COLOR: green">1、设定classpath</span><br />    <pre class="overflow"><path id="project.classpath"><br />        <fileset dir="${lib.dir}"><br />           <include name="*.jar"/><br />        </fileset><br />        <!-- cactus.properties文g需要放在lib.dir所对应的\径中 --><br />        <pathelement location="${lib.dir}"/><br />        <pathelement location="${tomcat.home}/common/lib/jsp-api.jar"/><br />        <pathelement location="${tomcat.home}/common/lib/servlet-api.jar"/><br />    </path></pre><br /><br /><span style="COLOR: green">2、定义相关Q?/span><br />   <pre class="overflow"><taskdef resource="cactus.tasks" classpathref="project.classpath"/><br />   <taskdef name="runservertests" classname="org.apache.cactus.integration.ant.RunServerTestsTask"><br />            <classpath><br />                <path refid="project.classpath"/><br />            </classpath><br />        </taskdef></pre><br /><br /><span style="COLOR: green">3、编译应用的cL件和试的类文g</span><br /><br /><span style="COLOR: green">4、打包整个应用ؓ(f)war文g</span><br />需要注意的是,不仅要打包应用类Q测试类也要打包<br />   <br />   <pre class="overflow"><target name="war" depends="compile.java"<br />            description="Generate the runtime war"><br /><br />        <war warfile="${target.dir}/${project.name}.war"<br />             webxml="${src.webapp.dir}/WEB-INF/web.xml"><br />            <fileset dir="${src.webapp.dir}"><br />                <exclude name="cactus-report.xsl"/><br />                <exclude name="WEB-INF/cactus-web.xml"/><br />                <exclude name="WEB-INF/web.xml"/><br />            </fileset><br />            <classes dir="${target.classes.java.dir}"/><br />            <!-- 别忘?jin)打包测试?--><br />            <classes dir="${target.classes.test.dir}"/><br />            <!-- 别忘?jin)打包各U相关的jar文g --><br />            < lib dir="project.classpath"/><br />        </war><br />    </target></pre><br /><br /><span style="COLOR: green">5、在应用的web.xml文g中添加测试所需的各U映?/span><br />cactus提供?jin)两个task来完成这个工作,CactifyWar和W(xu)ebXmlMerge?br />CactifyWar的功能是自动在已l打包的应用的web.xml文g中添加所需的映。WebXmlMerge是提供合q两个web.xml文g的功能?br /><pre class="overflow"><target name="test.prepare"<br />            depends="war, compile.cactus, test.prepare.logging"><br /><br />        <!-- Cactify the web-app archive --><br />        <cactifywar srcfile="${target.dir}/${project.name}.war"<br />                    destfile="${tomcat.home}/webapps/${project.name}-cactified.war"<br />                ><br />            <classes dir="${target.classes.java.dir}"/><br />            <classes dir="${target.classes.test.dir}"/><br />            <lib dir="project.classpath"/><br />       </cactifywar><br /></target></pre><br /><br /><span style="COLOR: green">6、运行测?/span><br />cactus提供?jin)cactus和RunServerTests两个task来运行测试?br />"cactus" task是通过复制容器服务器的最文件ƈq行来运行测试,因此需要制定容器服务器的类型,启动速度E快点,另外配置比较方便Q但是无法测试象tomcatq接池等资源。另外对tomcat5.5的支持也不好?br />"RunServerTests"是通过直接启动容器服务hq行试Q因此速度E慢Q且配置较麻?ch),但能试各种资源?br />   <pre class="overflow"><target name="test" depends="test.prepare"<br />             description="Run tests on Tomcat "><br /><br />        <!-- Start the servlet engine, wait for it to be started, run the<br />             unit tests, stop the servlet engine, wait for it to be stopped.<br />             The servlet engine is stopped if the tests fail for any reason --><br />        <!-- 8080是服务器的端口号Q?{project.name}-cactified是项目的路径Q和上一步的cactifywar 的destfile相对?--><br />        <runservertests<br />                testURL="http://localhost:8080/${project.name}-cactified/ServletRedirector?Cactus_Service=RUN_TEST"<br />                startTarget="_StartTomcat"<br />                stopTarget="_StopTomcat"<br />                testTarget="_Test"/><br /><br />    </target></pre><br />    <br />    <pre class="overflow"><!-- _Test是一个普通的junitd --><br />    <target name="_Test"><br />        <junit printsummary="yes" fork="yes"><br />            <classpath><br />                <path refid="project.classpath"/><br />                <pathelement location="${target.classes.java.dir}"/><br />                <pathelement location="${target.classes.test.dir}"/><br />            </classpath><br />            <formatter type="brief" usefile="false"/><br />            <formatter type="xml"/><br /><br />            <batchtest><br />                <fileset dir="${src.test.dir}"><br />                    <!-- Due to some Cactus synchronization bug, the 'unit' tests need<br />              to run before the 'sample' tests --><br />                    <include name="**/Test*.java"/><br />                    <exclude name="**/Test*All.java"/><br />                </fileset><br />            </batchtest><br />        </junit><br />    </target></pre></div> <img src ="http://www.aygfsteel.com/nbtymm/aggbug/52167.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/nbtymm/" target="_blank">nbt</a> 2006-06-12 11:48 <a href="http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52167.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JUnit 最?jng)_?转蝲)http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52115.htmlnbtnbtMon, 12 Jun 2006 01:39:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52115.htmlhttp://www.aygfsteel.com/nbtymm/comments/52115.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52115.html#Feedback0http://www.aygfsteel.com/nbtymm/comments/commentRss/52115.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/52115.html阅读全文

nbt 2006-06-12 09:39 发表评论
]]>
Cactus实例讲解(转蝲)http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52111.htmlnbtnbtMon, 12 Jun 2006 01:34:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52111.htmlhttp://www.aygfsteel.com/nbtymm/comments/52111.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52111.html#Feedback0http://www.aygfsteel.com/nbtymm/comments/commentRss/52111.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/52111.html

Cactus?/p>

Q ?

Cactus实现?jin)对JUnit试框架的无~扩展,可以方便地测试服务端应用E序。Cactus可以在下面几U情况下使用Q?/p>

  • 试Servlet以及(qing)M使用?jin)像HttpServletRequestQHttpServletResponseQ……这L(fng)对象的代码。用ServletTestCase?
  • 试Filter以及(qing)M使用?jin)像FilterConfigQ……这L(fng)对象的代码。用FilterTestCase?
  • 试JSP 。用ServletTestCase或JspTestCase?
  • 试Taglibs以及(qing)M使用?jin)像PageContextQ……这L(fng)对象的代码。用JspTestCase?
  • 试EJB。ServletTestCase或JspTestCase或FilterTestCase?

Cactus的用也是非常简单的Q你写的试cd需l承ServletTestCase或者JspTestCase、FilterTestCaseQ它们都l承?jin)JUnit的TestCaseQ。写好测试代码后需要启动web容器Q然后执行测试代码。在下面的章节中我们通过例子向你详细讲解?/p>

Cactus目Apache Jakarta Commons的一个子目Q网址是:(x)http://jakarta.apache.org/commons/cactus/?/p>

Q TestCase框架

在Cactus下,我们写的TestCase与JUnit有所不同Q先看一D代码,如下Q?/p>       public class TestSample extendsServletTestCase/JspTestCase/FilterTestCase {
       public TestSample (String testName) {
       super(testName);
       }
       public void setUp() {
       }
       public void tearDown() {
       }
       public void beginXXX(WebRequest theRequest) {
       }
       public void testXXX() {
       }
       public void endXXX(WebResponse theResponse) {
       }

上面是一个Cactus试cȝ完整代码框架Q其中的extends部分需要按你所试的不同目标来l承不同的类Q简介中有所描述Q?/p>

另外我们注意C个新的方法beginXXX和endXXX的,q两个方法分别会(x)在testXXX执行前和执行后执行,它们和setUp、tearDown不同的是beginXXX和endXXX?x)在相应的testXXX前执行,而setUp和tearDown则在每个testXXXҎ(gu)前都?x)执行。另外beginXXX和endXXX是客L(fng)代码Q所以在q两个方法里是无法用requestq样的服务端对象的?/p>

对于endXXXҎ(gu)需要另加说明的是,在Cactus v1.1前(包括v1.1Q,它的形式是这L(fng)public void endXXX(HttpURLConnection theConnection)Q而在Cactus v1.2开始它的Ş式有两种可能Q?/p>

  • public void endXXX(org.apache.cactus.WebResponse theResponse)Q?
  • public void endXXX(com.meterware.httpunit.WebResponse theResponse)Q?

可以看到区别在于引用的包不同Qؓ(f)什么会(x)q样的呢Q因为在v1.2开始Cactus集成?jin)HttpUnitq个lg。如果你熟?zhn)HttpUnitq个lgQ我惛_该明白ؓ(f)什么要集成HttpUnit。下面我们来看一D代码开比较一下两者的区别Q?/p>

public void endXXX(org.apache.cactus.WebResponse theResponse) {

String content = theResponse.getText();

assertEquals(content, "<html><body><h1>Hello world!</h1></body></html>");

}

public void endXXX(com.meterware.httpunit.WebResponse theResponse) {

WebTable table = theResponse.getTables()[0];

assertEquals("rows", 4, table.getRowCount());

assertEquals("columns", 3, table.getColumnCount());

assertEquals("links", 1, table.getTableCell(0, 2).getLinks().length);

}

当然Q在实际应用中你需要根据不同的需要来选择不同的endXXX。两个WebResponse的差别可以参见两者各自的API DocQ这里就不再多说?jin)?/p>

如何在Cactus里写试

Q 写测试代?/strong>

首先Q我们给?gu)类的代码,是一个ServletQ?/p>

public class SampleServlet extends HttpServlet {

public void doGet(HttpServletRequest theRequest,

HttpServletResponse theResponse) throws IOException {

PrintWriter pw = theResponse.getWriter();

theResponse.setContentType("text/html");

pw.print("<html><head/><body>");

pw.print("A GET request");

pw.print("</body></html>");

}

public String checkMethod(HttpServletRequest theRequest) {

return theRequest.getMethod();

}

}

Cactus中的试cL架已l在上面l出。下面来看一下例子,例子是从中Cactus自带的实例中抽取的一部分Q如下:(x)

public class TestSampleServlet extends ServletTestCase {

public void testReadServletOutputStream() throws IOException {

SampleServlet servlet = new SampleServlet();

servlet.doGet(request, response);

}

public void endReadServletOutputStream(WebResponse theResponse)

throws IOException {

String expected = "<html><head/><body>A GET request</body></html>";

String result = theResponse.getText();

assertEquals(expected, result);

}

public void beginPostMethod(WebRequest theRequest) {

theRequest.addParameter("param", "value", WebRequest.POST_METHOD);

}

public void testPostMethod() {

SampleServlet servlet = new SampleServlet();

assertEquals("POST", servlet.checkMethod(request));

assertEquals("value", request.getParameter("param"));

}

}

W一个方法testReadServletOutputStreamQ调用doGetQ相当于在客L(fng)提交hQ然后在Servlet处理后会(x)产生一个回馈,所以,在endReadServletOutputStreamҎ(gu)里,我们通过调用response的相应方法判断回馈是否符合预期结果?/p>

W二个方法testPostMethodQ在q之前有一个beginPostMethodQ在q个Ҏ(gu)里我们以POST方式往request里增加一个表单数据paramQgؓ(f)”value”。下面在testPostMethod我们p验证表单数据是否以POST方式提交C(jin)服务端的Servlet里,所以,我们看到?jin)两个assertEqualsQ分别进行了(jin)判断。在q里我们要注意到beginPostMethodҎ(gu)中的theRequest和testPostMethod中的request的区别,在前面我们已l提到过QbeginPostMethod是在客户端执行的Q所以它Ҏ(gu)内的所有操作事实上是模拟页面操作的Q比如上面的讄表单数据Q而testPostMethod是服务端执行的,其中的request也是服务端的?/p>配置cactus.properties和web.xml

cactus.properties

  • cactus.contextURL

q个属性是必须的,它指定了(jin)web应用的访问地址

例:(x)cactus.contextURL = http://localhost:8080/test

  • cactus.servletRedirectorName

可选,当测试类l承ServletTestCase时用于指定Cactus Servlet Redirector的映名U。默认:(x)ServletRedirector

例:(x)cactus.servletRedirectorName = ServletRedirector

  • cactus.jspRedirectorName

可选,当测试类l承ServletTestCase时用于指定Cactus Jsp Redirector的映名U。默认:(x)ServletRedirector

例:(x)cactus.jspRedirectorName = JspRedirector

可选,当测试类l承ServletTestCase时用于指定Cactus Filter Redirector的映名U。默认:(x)ServletRedirector

例:(x)cactus.filterRedirectorName = FilterRedirector

Cactus.properties你可以放|在WEB-INF/classes/下?/p>

web.xml

在web.xml里要为相应的试cL定相应的Cactus Redirector?/p>

ServletTestCase对应org.apache.cactus.server.ServletTestRedirector

JspTestCase对应/jspRedirector.jsp

FilterTestCase对应org.apache.cactus.server.FilterTestRedirector

<web-app>

<filter>

<filter-name>FilterRedirector</filter-name>

<filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>

</filter>

<filter-mapping>

<filter-name>FilterRedirector</filter-name>

<url-pattern>/FilterRedirector</url-pattern>

</filter-mapping>

<servlet>

<servlet-name>ServletRedirector</servlet-name>

<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>

</servlet>

<servlet>

<servlet-name>JspRedirector</servlet-name>

<jsp-file>/jspRedirector.jsp</jsp-file>

</servlet>

<servlet-mapping>

<servlet-name>ServletRedirector</servlet-name>

<url-pattern>/ServletRedirector</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>JspRedirector</servlet-name>

<url-pattern>/JspRedirector</url-pattern>

</servlet-mapping>

</web-app>

如果你的试cȝ承了(jin)JspTestCase则需要将jspRedirector.jsp文g攄C在web.xml中指定的路径里?/p>

安装说明

  • 在用CactusӞstrutstest.jarq需要有下列包的支持。包可放|在WEB-INF/lib?

如下Q?/p>

junit.jar

servlet.jar

cactus.jar

httpclient.jar

commons-logging.jar

httpunit.jarQTidy.jarQxerces.jarQ可选,如果你集成了(jin)httpunit的话需要,也就是在endXXX中用了(jin)httpunitQ?/p>

    • Server端(也就是web容器Q需要如下包

cactus.jar

junit.jar

aspectjrt.jar

commons-logging.jar

  • 写好试代码后将class攄在WEB-INF/classes?
  • 被测代码也放|在WEB-INF/classes?
  • 写好cactus.properties和web.xml两个配置文g
  • 启动web容器
  • q行试代码


nbt 2006-06-12 09:34 发表评论
]]>
JDBCq接大全http://www.aygfsteel.com/nbtymm/archive/2006/06/12/52104.htmlnbtnbtMon, 12 Jun 2006 01:11:00 GMThttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52104.htmlhttp://www.aygfsteel.com/nbtymm/comments/52104.htmlhttp://www.aygfsteel.com/nbtymm/archive/2006/06/12/52104.html#Feedback0http://www.aygfsteel.com/nbtymm/comments/commentRss/52104.htmlhttp://www.aygfsteel.com/nbtymm/services/trackbacks/52104.html
  一、连接各U数据库方式速查?/b>

  下面|列?jin)各U数据库使用JDBCq接的方式,可以作ؓ(f)一个手册用?

  1、Oracle8/8i/9i数据库(thin模式Q?

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);

  2、DB2数据?

Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample"; //sampleZ的数据库?
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);

  3、Sql Server7.0/2000数据?

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);

  4、Sybase数据?

Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDBZ的数据库?
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);

  5、Informix数据?

Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword"; //myDB为数据库?
Connection conn= DriverManager.getConnection(url);

  6、MySQL数据?

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB为数据库?
Connection conn= DriverManager.getConnection(url);

  7、PostgreSQL数据?

Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库?
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);

  8、access数据库直q用ODBC?br />
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
Connection conn = DriverManager.getConnection(url,"","");
Statement stmtNew=conn.createStatement() ;

  二、JDBCq接MySql方式

  下面是用JDBCq接MySql的一个小的教E?

  1、查N动程?br />
  MySQL目前提供的java驱动E序为Connection/JQ可以从MySQL官方|站下蝲Qƈ扑ֈmysql-connector-java-3.0.15-ga-bin.jar文gQ此驱动E序为纯java驱动E序Q不需做其他配|?br />
  2、动态指定classpath

  如果需要执行时动态指定classpathQ就在执行时采用Qcp方式。否则将上面?jar文g加入到classpath环境变量中?br />
  3、加载驱动程?br />
try{
 Class.forName(com.mysql.jdbc.Driver);
 System.out.println(Success loading Mysql Driver!);
}catch(Exception e)
{
 System.out.println(Error loading Mysql Driver!);
 e.printStackTrace();
}

  4、设|连接的url

jdbcQmysqlQ?/localhost/databasename[?pa=va][Qpa=va]

  三、以下列Z(jin)在用JDBC来连接Oracle数据库时可以使用的一些技?/b>

  1、在客户端Y件开发中使用Thin驱动E序

  在开发Java软g斚wQOracle的数据库提供?jin)四U类型的驱动E序Q二U用于应用Y件、applets、servlets{客L(fng)软gQ另外二U用于数据库中的Java存储q程{服务器端Y件。在客户机端软g的开发中Q我们可以选择OCI驱动E序或Thin驱动E序。OCI驱动E序利用Java本地化接口(JNIQ,通过Oracle客户端Y件与数据库进行通讯。Thin驱动E序是纯Java驱动E序Q它直接与数据库q行通讯。ؓ(f)?jin)获得最高的性能QOracle在客L(fng)软g的开发中使用OCI驱动E序Q这g是正的。但我徏议用Thin驱动E序Q因为通过多次试发现Q在通常情况下,Thin驱动E序的性能都超q了(jin)OCI驱动E序?br />
  2、关闭自动提交功能,提高pȝ性能

  在第一ơ徏立与数据库的q接Ӟ在缺省情况下Q连接是在自动提交模式下的。ؓ(f)?jin)获得更好的性能Q可以通过调用带布?yu)(dng)值false参数的ConnectioncȝsetAutoCommit()Ҏ(gu)关闭自动提交功能Q如下所C:(x)

  conn.setAutoCommit(false);

  值得注意的是Q一旦关闭了(jin)自动提交功能Q我们就需要通过调用Connectioncȝcommit()和rollback()Ҏ(gu)来h工的方式对事务进行管理?br />
  3、在动态SQL或有旉限制的命令中使用Statement对象

  在执行SQL命o(h)Ӟ我们有二U选择Q可以用PreparedStatement对象Q也可以使用Statement对象。无论多次C用同一个SQL命o(h)QPreparedStatement都只对它解析和编译一ơ。当使用Statement对象Ӟ每次执行一个SQL命o(h)Ӟ都会(x)对它q行解析和编译。这可能?x)你认为,使用PreparedStatement对象比用Statement对象的速度更快。然而,我进行的试表明Q在客户端Y件中Q情况ƈ非如此。因此,在有旉限制的SQL操作中,除非成批地处理SQL命o(h)Q我们应当考虑使用Statement对象?br />
  此外Q用Statement对象也得编写动态SQL命o(h)更加单,因ؓ(f)我们可以字W串q接在一P建立一个有效的SQL命o(h)。因此,我认为,Statement对象可以使动态SQL命o(h)的创建和执行变得更加单?br />
  4、利用helper函数对动态SQL命o(h)q行格式?br />
  在创Z用Statement对象执行的动态SQL命o(h)Ӟ我们需要处理一些格式化斚w的问题。例如,如果我们惛_Z个将名字O'Reilly插入表中的SQL命o(h)Q则必须使用二个相连的?'”号替换O'Reilly中的?”号。完成这些工作的最好的Ҏ(gu)是创Z个完成替换操作的helperҎ(gu)Q然后在q接字符串心(j)服用公式表达一个SQL命o(h)Ӟ使用创徏的helperҎ(gu)。与此类似的是,我们可以让helperҎ(gu)接受一个Date型的|然后让它输出ZOracle的to_date()函数的字W串表达式?br />
  5、利用PreparedStatement对象提高数据库的M效率

  在用PreparedStatement对象执行SQL命o(h)Ӟ命o(h)被数据库q行解析和编译,然后被放到命令缓冲区。然后,每当执行同一个PreparedStatement对象Ӟ它就?x)被再解析一ơ,但不?x)被再次~译。在~冲Z可以发现预编译的命o(h)Qƈ且可以重C用。在有大量用L(fng)企业U应用Y件中Q经怼(x)重复执行相同的SQL命o(h)Q用PreparedStatement对象带来的编译次数的减少能够提高数据库的M性能。如果不是在客户端创建、预备、执行PreparedStatementd需要的旉长于StatementdQ我?x)徏议在除动态SQL命o(h)之外的所有情况下使用PreparedStatement对象?br />
  6、在成批处理重复的插入或更新操作中用PreparedStatement对象

  如果成批地处理插入和更新操作Q就能够显著地减它们所需要的旉。Oracle提供的Statement?CallableStatementq不真正地支持批处理Q只有PreparedStatement对象才真正地支持批处理。我们可以用addBatch()和executeBatch()Ҏ(gu)选择标准的JDBC批处理,或者通过利用PreparedStatement对象的setExecuteBatch()Ҏ(gu)和标准的executeUpdate()Ҏ(gu)选择速度更快的Oracle专有的方法。要使用Oracle专有的批处理机制Q可以以如下所C的方式调用setExecuteBatch()Q?br />
PreparedStatement pstmt3D null;
try {
 ((OraclePreparedStatement)pstmt).setExecuteBatch(30);
 ...
 pstmt.executeUpdate();
}

  调用setExecuteBatch()时指定的值是一个上限,当达到该值时Q就?x)自动地引发SQL命o(h)执行Q标准的executeUpdate()Ҏ(gu)׃(x)被作为批处理送到数据库中。我们可以通过调用PreparedStatementcȝsendBatch()Ҏ(gu)随时传输批处理Q务?br />
  7、用Oracle locatorҎ(gu)插入、更新大对象QLOBQ?br />
  Oracle的PreparedStatementcM完全支持BLOB和CLOB{大对象的处理,其是Thin驱动E序不支持利用PreparedStatement对象的setObject()和setBinaryStream()Ҏ(gu)讄BLOB的|也不支持利用setCharacterStream()Ҏ(gu)讄CLOB的倹{只有locator本n中的Ҏ(gu)才能够从数据库中获取LOBcd的倹{可以用PreparedStatement对象插入或更新LOBQ但需要用locator才能获取LOB的倹{由于存在这二个问题Q因此,我徏议用locator的方法来插入、更新或获取LOB的倹{?br />
  8、用SQL92语法调用存储q程

  在调用存储过E时Q我们可以用SQL92或Oracle PL/SQLQ由于用Oracle PL/SQLq没有什么实际的好处Q而且?x)给以后l护你的应用E序的开发h员带来麻?ch),因此Q我在调用存储过E时使用SQL92?br />
  9、用Object SQL对象模式{Ud数据库中

  既然可以Oracle的数据库作ؓ(f)一U面向对象的数据库来使用Q就可以考虑应用程序中的面向对象模式{到数据库中。目前的Ҏ(gu)是创建Java bean作ؓ(f)伪装的数据库对象Q将它们的属性映到关系表中Q然后在q些bean中添加方法。尽这样作在Java中没有什么问题,但由于操作都是在数据库之外进行的Q因此其他访问数据库的应用Y件无法利用对象模式。如果利用Oracle的面向对象的技术,可以通过创徏一个新的数据库对象cd在数据库中模仿其数据和操作,然后使用JPublisher{工L(fng)成自qJava beancR如果用这U方式,不但Java应用E序可以使用应用软g的对象模式,其他需要共享你的应用中的数据和操作的应用Y件也可以使用应用软g中的对象模式?br />
  10、利用SQL完成数据库内的操?br />
  我要向大家介l的最重要的经验是充分利用SQL的面向集合的Ҏ(gu)来解x据库处理需求,而不是用Java{过E化的编E语a?br />
  如果~程人员要在一个表中查找许多行Q结果中的每个行都会(x)查找其他表中的数据,最后,~程人员创徏?jin)独立的UPDATE命o(h)来成批地更新W一个表中的数据。与此类似的d可以通过在set子句中用多列子查询而在一个UPDATE命o(h)中完成。当能够在单一的SQL命o(h)中完成Q务,何必要让数据在网上流来流ȝQ我用户认真学习(fn)如何最大限度地发挥SQL的功能?/span>

nbt 2006-06-12 09:11 发表评论
]]>
վ֩ģ壺 | | | ƾ| | | | | Ͻ| ˮ| Դ| | ͼʲ| ء| | | | ԭ| | Ԫ| | | Ϫ| | | ߷| ɽ| | | ͨ| | | Ӫ| | | ̨ɽ| | | ʻ| ƺ| ¤|