如果您只希望 vxml 的数据库连接,请尝试使用 subdialog 标记并调用 servlet(或 JSP)。
[服务器 VXML JSP (URL=http://hostname:port/app_name/sample.jsp)]
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="application/voicexml+xml; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE vxml PUBLIC "-//W3C//DTD VOICEXML 2.1//EN" "http://www.w3.org/TR/voicexml21/vxml.dtd">
<%@ page import="import java.sql.*" %>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<script><![CDATA[
<%
out.println("var myObject = new Array();");
// Set character encoding
request.setCharacterEncoding("UTF-8");
// Get VXML parameter.
String input1 = request.getParameter("input1");
String input2 = request.getParameter("input2");
String input3 = request.getParameter("input3");
ResultSet rs = null:
//
// Execute SQL
//
int i = 0;
while(rs.next()) {
String value1 = rs.getString("column1")
String value2 = rs.getString("column2")
String value3 = rs.getString("column3")
out.println("myObject[" + i + "] = new Object();");
out.println("myObject[" + i + "].column1 = " + value1 + ";");
out.println("myObject[" + i + "].column2 = " + value2 + ";");
out.println("myObject[" + i + "].column3 = " + value3 + ";");
i++;
}
rs.close();
%>
]]></script>
<form id="response">
<block>
<return namelist="myObject" />
</block>
</form>
</vxml>
[客户端 VXML 文本]
<form id="database_connection_sample">
<subdialog
name="database_connection_subdialog"
method="post"
srcexpr="'http://hostname:port/app_name/sample.jsp'"
maxage="0"
maxstale="0"
namelist="input1 input2 input3">
<filled>
<!-- Get Result Object -->
<assign name="resultObject" expr="database_connection_subdialog.myObject" />
</filled>
</subdialog>
<catch event="error">
<!-- Error Handling-->
</catch>
<block>
<goto next="#next_form" />
</block>
</form>
获取数据库值表达式示例 -> "resultObject[0].column1"