Example #2: Allowing the user to specify the host to connect to using an HTML form

Administrators may also want to use HTML forms to specify override values rather than calculating them. The following example displays a simple form for entry of a host name. The form posts to a JSP program which uses the host name specified in the form to override the host name in the 3270 Session.

This example is written using JSP. The Deployment Wizard was used to create an HTML file that contains two sessions named "3270 Display" and "5250 Display." Note that in Z and I Emulator for Web 2.0, some of the HTML is generated using JavaScript, and HTML parameters are specified within a JavaScript array or using JavaScript document.write statements.

When using forms, the form data needs to be retained across requests to the program. This is because Z and I Emulator for Web HTML files reload themselves for Java detection and for bookmarking support when using configuration server-based model pages. If Java 1 is selected and bookmarking support is disabled if using the configuration server-based model, the page will not need to reload and there is no need to retain the form data. This example uses a JSP session to store the form data across reloads.

Here is a simple HTML form that allows for entry of a host name. The form posts to the JSP program (example2.jsp):

<form method="POST"  action="zieweb/example2.jsp">
Hostname <input name="form.hostname"><br>
<input type="submit">
</form>

Here is the modified output from the Deployment Wizard. See the comments in the example for more detail. The lines added to the Deployment Wizard output are displayed in bold.

<HTML>
<%
// Get a session or create if necessary and store the hostname
// entered in the form in the session.
HttpSession session = request.getSession(true);
String hostname = request.getParameter("form.hostname");
if (hostname!=null) {
session.putValue("session.hostname", hostname);
}
%>
<!-- ZIEWeb WIZARD HTML -->
<!-- Deployment Wizard Build : 8.0.0-B20030605 -->
<HEAD>
<META http-equiv="content-type" content="text/html; charset=UTF-8">
<TITLE>Example 2 page title</TITLE>
<SCRIPT LANGUAGE="JavaScript" SRC="/zieweb/CommonJars.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="/zieweb/HODJavaDetect.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="/zieweb/CommonParms.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">

//---- Start JavaScript variable declarations ----//
var zie_Locale = '';
var zie_jsapi=false;
var zie_AppName ='';
var zie_AppHgt = '80%';
var zie_AppWid = '80%';
var zie_CodeBase = '/zieweb/';
var zie_FinalFile = 'z_example2.html';
var zie_JavaType = 'java2';
var zie_Obplet = '';
var zie_jars = 'habasen.jar,ziebasen.jar,zieimg.jar,hacp.jar,ziesignn.jar,ha3270n.jar,
                ziecfgn.jar,ha5250n.jar';

var zie_URL = new String(window.location);
var zie_DebugOn = false;
var zie_SearchArg = window.location.search.substring(1);

var zie_AppletParams = new Array;
zie_AppletParams[0] = '<PARAM NAME="ParameterFile" VALUE="ZIEWebData\\example2\\params.txt">';
zie_AppletParams[1] = '<PARAM NAME="ShowDocument"  VALUE="_parent">';
zie_AppletParams[2] = '<PARAM NAME="JavaScriptAPI" VALUE="' + zie_jsapi + '">';
zie_AppletParams[3] = '<PARAM NAME="PreloadComponentList" VALUE="HABASE;HODBASE;HODIMG;
                                                                    HACP;HAFNTIB;HAFNTAP;
                                                                    HA3270;HODCFG;HA5250">';

// The next 2 lines are required in order to override session properties.
// The first line turns on the processing for this function and does not
// need to be modified. The second line identifies the sessions that you
// want to change. In this example, there are 2 sessions identified
// named: "3270 Display" and "5250 Display".
// Be careful to increment the array index correctly.

zie_AppletParams[4] = <PARAM NAME="EnableHTMLOverrides" VALUE="true">;
zie_AppletParams[5] = <PARAM NAME="TargetedSessionList" VALUE="3270 Display,5250 Display">;

// The following line changes the Host or Destination Address session parameter
// for the session named "3270 Display". In this example, the Host is being set
// to the value saved in the JSP session from the HTML form.
// When you are initially testing your changes, you may want to use a constant
// value to verify that the syntax is correct before you insert your
// calculations.
// Here we override the host for the 3270 session to the value saved in the
// jsp session from the html form.

zie_AppletParams[6] = <PARAM NAME="Host" VALUE="3270 
                       Display=<%=session.getValue("session.hostname")%>">;

//zie_AppletParams[x] = '<PARAM NAME="DebugCode"     VALUE="65535">';

//---- End JavaScript variable declarations ----//

function getZIEMsg(msgNum) {
  return ZIEFrame.zieMsgs[msgNum];
}

function getZIEFrame() {
  return ZIEFrame;
}

var lang = detectLanguage(zie_Locale);
document.writeln('<FRAMESET cols="*,10" border=0 FRAMEBORDER="0">');
document.writeln('<FRAME    src="/zieweb/ziedetect_' + lang + '.html" name="ZIEFrame">');
document.writeln('</FRAMESET>');

</SCRIPT>
</HEAD>
</HTML>