用 ASP 文件来调用 Servlet

在 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>
posted @ 2005-12-07 13:10  Aowind  阅读(1305)  评论(1编辑  收藏  举报