<% //-------------------------------------------------------------------------------- // File : menu.jsp // Description : This is a sample JSP code to generate a VXML menu. // Input parameters : - maintainer -- email address to receive trace log. (optional) // - choiceX -- choices of the menu. // - urlX -- URLs of choices. // - audioX -- wave files to play audio choices. (optional) // where X is 1,2,3... etc. // Output : A VXML document with a menu of choices that have the // corresponding url and audio file for each choice. // // Example: // URL : http://cafe.bevocal.com/libraries/jsp/menu.jsp?maintainer=test@bevocal.com&choice1=Test one&choice2=Test two&audio1=audio1.wav&audio2=audio2.wav&url1=test1.vxml&url2=test2.vxml // Result: // // // // // Welcome to menu generator. Please choose one of the following // // // // I'm sorry. There's no help available here. // I'm sorry. I didn't hear anything. // I didn't get that. // // // Notes: // - maintainer and audio inputs are optional. // - For each choice name, there must be a corresponding url name, i.e. choice5 // requires url5. Otherwise, the choice will not be generated. // - If the input URL has passing parameters, the URL must be encoded before // passing to menu.jsp. //-------------------------------------------------------------------------------- response.setContentType("application/voicexml+xml"); out.println(""); //-------------------------------------------------------------------------------- //Include files go here: //--------------------------------------------------------------------------------%> <%@ page import="java.util.*" %> <%@ page import="java.net.URLEncoder" %> <% //-------------------------------------------------------------------------------- //Gathering input parameters including maintainer and a list of choice names: //-------------------------------------------------------------------------------- //Obtaining maintainer value: String maintainer = request.getParameter("maintainer"); if (maintainer == null) { maintainer = ""; } //Obtaining all parameter names of the request: Enumeration paramNames = request.getParameterNames(); //Constructing a vector of choice names from the list of parameter names: Vector choices = new Vector(); if (paramNames != null) { while (paramNames.hasMoreElements()) { String tempStr = (String) paramNames.nextElement(); if (tempStr.indexOf("choice") == 0) { choices.add(tempStr); } } } //-------------------------------------------------------------------------------- //Generating vxml menu: //-------------------------------------------------------------------------------- //Generating VXML header: out.println(""); //Generating meta tag for maintainer if needed: if (!maintainer.equals("")) { out.println(""); } //Generating the menu if there is at least one choice: int numChoices = choices.size(); if (numChoices > 0) { try { //Generating menu tag and welcome prompt: out.println(""); out.println(" Welcome to menu generator. Please choose one of the following "); //Generating choices for valid input choice and url: for (int i = numChoices - 1; i >= 0; i--) { //Obtaining choice number, i.e. 1 or 2 or 3 etc. String suffix = ((String) choices.elementAt(i)).substring(6); //Obtaining the value for a choice including choice value, url and audio file. String tempChoice = request.getParameter("choice" + suffix); String tempUrl = request.getParameter("url" + suffix); String tempAudio = request.getParameter("audio" + suffix); //Do not generate choice for unavailable url: if (tempUrl != null && !tempUrl.equals("")) { //Generating choice with audio tag if audio file is available: if (tempAudio != null && !tempAudio.equals("")) { out.println(" "); } //Generating choice with no audio tag: else { out.println(" " + tempChoice + ""); } } } out.println(""); //Generating default prompt for help, no input or no match: out.println("I'm sorry. There's no help available here."); out.println(" I'm sorry. I didn't hear anything. "); out.println(" I didn't get that. "); } catch (Exception e) { out.println("Exception: " + e.toString()); } } //Generate no choice message if there is no input choice. else { out.println("
"); out.println(" Welcome to menu generator. There is no choice. Good bye. "); out.println("
"); } //Generating the close vxml tag: out.println("
"); %>