如何測(cè)試JSP容器

這篇文章給大家分享的是有關(guān)如何測(cè)試JSP容器的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的阜城網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

由于上面給出例 復(fù)雜 。一般人很難理解。我也是 ^_^但仔細(xì)看我還是自己寫出一個(gè)比較簡(jiǎn)單的,望大家一起討論。被測(cè)試JSP容器

<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %> <%@ taglib prefix="c" uri="/WEB-INF/c-1_0-rt.tld" %> <html:html> <c:if test="${name != pass}"> ${name}  <br> ${pass} <br> <!-- <html:text property="in" ></html:text> --> </c:if> </html:html>

ant直接把他放在 eclipes 工程的根目錄下 build.xml但有有3個(gè)參數(shù)要設(shè)置 tomcat.home Tomcat 的地址webapp.path 工程中的根目錄,下面有WEB-INFsrc 原代碼 (到時(shí)候JSP會(huì)翻譯成.java到這個(gè)目錄的 org.apache.JSP.JSP 下)

<project name="Webapp Precompilation" default="all" basedir="."> <!-- tomcat dir --> <property name="tomcat.home" value="D:\Tomcat 5.0"/> <!-- this=..//WEB-INF (in eclipes)  -->   <property name="webapp.path" value=".\WebRoot"/> <!-- src (in eclipes) --> <property name="src" value="./src"/> <target name="jspc"> <taskdef classname="org.apache.jasper.JspC" name="jasper2" > <classpath id="jspc.classpath"> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home}/bin"> <include name="*.jar"/> </fileset> <fileset dir="${tomcat.home}/server/lib"> <include name="*.jar"/> </fileset> <fileset dir="${tomcat.home}/common/lib"> <include name="*.jar"/> </fileset> </classpath> </taskdef> <jasper2 validateXml="false" uriroot="${webapp.path}" webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml" outputDir="${src}" /> </target> <target name="compile"> <mkdir dir="${webapp.path}/WEB-INF/classes"/> <mkdir dir="${webapp.path}/WEB-INF/lib"/> <javac destdir="${webapp.path}/WEB-INF/classes" optimize="off" debug="on" failonerror="false" srcdir="${src}" excludes="**/*.smap"> <classpath> <pathelement location="${webapp.path}/WEB-INF/classes"/> <fileset dir="${webapp.path}/WEB-INF/lib"> <include name="*.jar"/> </fileset> <pathelement location="${tomcat.home}/common/classes"/> <fileset dir="${tomcat.home}/common/lib"> <include name="*.jar"/> </fileset> <pathelement location="${tomcat.home}/shared/classes"/> <fileset dir="${tomcat.home}/shared/lib"> <include name="*.jar"/> </fileset> <fileset dir="${tomcat.home}/bin"> <include name="*.jar"/> </fileset> </classpath> <include name="**" /> <exclude name="tags/**" /> </javac> </target> <target name="all" depends="jspc,compile"> </target> <target name="cleanup"> <delete> <fileset dir="${webapp.path}/WEB-INF/src"/> <fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/> </delete> </target> </project>

TEST

package jetty.test.supper;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse;  import org.apache.jsp.jsp.MyJsp_jsp;  import com.meterware.httpunit.GetMethodWebRequest;  import com.meterware.httpunit.WebRequest;  import com.meterware.httpunit.WebResponse;  import com.meterware.servletunit.InvocationContext;  import com.meterware.servletunit.ServletRunner;  import com.meterware.servletunit.ServletUnitClient;  import junit.framework.TestCase;  public class JSPCTest extends TestCase{  private InvocationContext ic = null ;  protected void setUp() throws Exception {  ServletRunner sr = new ServletRunner();  // 向環(huán)境中注冊(cè) jsp           sr.registerServlet("HelloWorld", MyJsp_jsp.class.getName());  ServletUnitClient  sc = sr.newClient();  WebRequest request = new GetMethodWebRequest("http://localhost/HelloWorld");  ic = sc.newInvocation(request);  }  public void testJspC() throws Exception{  HttpServletRequest re =  ic .getRequest();  HttpServletResponse rq =  ic.getResponse();  re.setAttribute("name","liukaiyi");  re.setAttribute("pass","123456");  MyJsp_jsp is = (MyJsp_jsp) ic.getServlet();  is._jspService(re,rq);  WebResponse response = ic.getServletResponse();  // 輸出          System.out.println( response.getText() );  }  }

結(jié)果是

<html> liukaiyi  <br> 123456 <br> </html>

感謝各位的閱讀!關(guān)于“如何測(cè)試JSP容器”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

新聞名稱:如何測(cè)試JSP容器
瀏覽地址:http://bm7419.com/article26/igisjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、標(biāo)簽優(yōu)化App設(shè)計(jì)、網(wǎng)站營銷靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)