在 WebSphere應用伺服器 中的 ASP 支援包括一個用於嵌入 Servlet 的 ActiveX 控制,下面介紹ActiveX 控制AspToServlet 的方法和屬性。
該方法說明如下:
(1) String ExecServletToString(String servletName);執行 ServletName,並將其輸出返回到一個字串中。
(2) ExecServlet(String servletName);執行 ServletName,並將其輸出直接發送至 HTML 頁面。
(3) String VarValue(String varName);獲得一預置變數值(其它格式)。
(4) VarValue(String varName, String newVal);設定變數值。變數佔據的總大小應小於 0.5 個千字
節(Kbyte)。且僅對設定檔使用這些變數。
其屬性如下:
= Boolean WriteHeaders;若該屬性為真,則 Servlet 提供的標題被寫入使用者處。預設值為假。
= Boolean OnTest;若該屬性為真,伺服器會將訊息記錄到產生的 HTML 頁面中。預設值為假。
下列ASP 指令碼樣本是以 Microsoft Visual Basic Scripting(VBScript)書寫的。
〈%
´ Small sample asp file to show the capabilities of the servlets and the ASP GateWay ...
%>
〈H1> Starting the ASP->Java Servlet demo〈/H1>
〈%
´ Create a Servlet gateway object and initialize it ...
Set javaasp = Server.CreateObject("AspToServlet.AspToServlet")
´ Setting these properties is only for the sake of demo.
´ These are the default values ...
javaasp.OnTest = False
javaasp.WriteHeaders = False
´ Add several variables ...
javaasp.VarValue("gal") = "lag"
javaasp.VarValue("pico")= "ocip"
javaasp.VarValue("tal") = "lat"
javaasp.VarValue("paz") = "zap"
javaasp.VarValue("variable name with spaces") = "variable value with spaces"
%>
〈BR>
Lets check the variables
〈%
Response.Write("variable gal = ")
Response.Write(javaasp.VarValue("gal"))
%>
〈BR>
〈%
Response.Write("variable pico = " & javaasp.VarValue("pico"))
%>
〈BR>
〈HR>
〈%
galout = javaasp.ExecServletToString("SnoopServlet")
If javaasp.WriteHeaders = True Then
%>
Headers were written 〈%
Else
%>
Headers were not written 〈%
End If
Response.Write(galout)
%>
〈H1> The End ...〈/H1>