This is a sample Java Server Page (JSP) application using J2HODScreenableRecord as a screen record. It is an example of a TN3270 application running in a managed environment.
This sample JSP file, JNDIClientScreenableSample.jsp, is also located in the directory ...\samples\tn3270\. The output generated from executing it is in the file ...\samples\tn3270\JNDIClientScreenableSampleOutput.html.
<%
%>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.naming.directory.*" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="com.ibm.connector2.spi.*" %>
<%@ page import="com.ibm.connector2.cci.*" %>
<%@ page import="com.ibm.connector2.poolmanager.*" %>
<%@ page import="com.ibm.connector2.hod.*" %>
<%@ page import="com.ibm.connector2.hod.screenable.*" %>
<%
/**
* An implementation of the application client. It accesses the connector using JNDI
* lookup mechanism.
*/
out.println ("<pre>");
out.println ("Main - Enter<br>");
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
String USERID = "TestID";
String PASSWORD = "Passwd";
try
{ //try
// Create the initial context
Context ctx = new InitialContext(env);
// get Connection Factory via JNDI lookup and close Context
out.println ("JNDI trying to look up...");
J2HODConnectionFactory cf = (J2HODConnectionFactory) ctx.lookup("eis/j2hod_cf");
out.println("JNDI lookup successfull: " + cf+"<br>");
ctx.close();
out.println("trying getManagedConnectionFactory...");
J2HOD3270ManagedConnectionFactory mcf = (J2HOD3270ManagedConnectionFactory)cf.getManagedConnectionFactory();
out.println("getManagedConnectionFactory successfull: " + mcf.toString());
out.println("ServerName/Port Number = " + mcf.getServerName() + " / " + mcf.getPortNumber() + "<br>");
// set up properties
J2HODConnectionSpec connectionSpec = new J2HODConnectionSpec();
connectionSpec.setUserName("j2chod"); //specify according to your setting
connectionSpec.setPassword("connector"); //specify according to your setting
// create connection
out.println("trying getConnection...");
J2HODConnection connection = (J2HODConnection)cf.getConnection(connectionSpec);
out.println("getConnection successfull: " + connection.toString() + "<br>");
// create screenable record instances to represent each screen
J2HODScreenableRecord logonScreen = new J2HODScreenableRecord();
J2HODScreenableRecord msgScreen = new J2HODScreenableRecord();
// create interaction
J2HODInteraction interaction = (J2HODInteraction)connection.createInteraction();
J2HODInteractionSpec interactionSpec;
// set interactionSpec as RECEIVE mode with output screen recognition description
interactionSpec = new J2HODInteractionSpec();
interactionSpec.setExecutionTimeout(new Integer(60000));
interactionSpec.setInteractionVerb(new Integer(J2HODInteractionSpec.SYNC_RECEIVE));
interactionSpec.setScreenName("Logon Screen");
interactionSpec.setRecognizeRow(new Integer(20));
interactionSpec.setRecognizeColumn(new Integer(2));
interactionSpec.setRecognizeString("USERID ===>");
out.println ("trying execute with SYNC_RECEIVE");
if (connection.execute(interactionSpec, null, logonScreen))
out.println ("successful execution with Matching return screen");
else
out.println ("successful execution with NON-Matching return screen");
out.println ("connection.execute(receive logonScreen) done.<br>");
// print each field information from logonScreen
out.println ("total number of fields in logonScreen = "+logonScreen.getFieldCount());
out.print ("<font color=#008800>");
Iterator it = logonScreen.getFields();
int fCount=0;
while (it.hasNext())
{ //print each fields on screen
fCount++;
J2HODFieldRecord fieldRec = (J2HODFieldRecord)it.next();
out.println ("field["+fCount+"] = ["+fieldRec.getText()+"]");
}
out.println ("</font><br>");
// set interactionSpec as SEND-RECEIVE mode with output screen recognition description
interactionSpec = new J2HODInteractionSpec();
interactionSpec.setExecutionTimeout(new Integer(60000));
interactionSpec.setInteractionVerb(new Integer(J2HODInteractionSpec.SYNC_SEND_RECEIVE));
interactionSpec.setKeyName("ENTER");
interactionSpec.setScreenName("Message Screen");
interactionSpec.setRecognizeRow(new Integer(4));
interactionSpec.setRecognizeColumn(new Integer(1));
interactionSpec.setRecognizeString("Enter one of the following commands:");
// set ID and PW - begin
out.println ("setting ID/PW to logonScreen - begin");
logonScreen.getField(54).setText(USERID); //get and set ID field
logonScreen.getField(57).setText(PASSWORD); //get and set PW field
out.println ("setting ID/PW to logonScreen - done");
// set ID and PW - end
out.println ("trying to execute with SYNC_SEND_RECEIVE");
if (connection.execute(interactionSpec, logonScreen, msgScreen))
out.println ("successful execution with Matching return screen");
else
out.println ("successful execution with NON-Matching return screen");
out.println ("connection.execute(send logonScreen, receive msgScreen) done.<br>");
// print each field information from msgScreen
out.println ("total number of fields in msgScreen = "+msgScreen.getFieldCount());
out.print ("<font color=#008800>");
it = msgScreen.getFields();
fCount=0;
while (it.hasNext())
{
fCount++;
J2HODFieldRecord fieldRec = (J2HODFieldRecord)it.next();
out.println ("field["+fCount+"] = ["+fieldRec.getText()+"]");
}
out.println ("</font><br>");
// set interactionSpec as SEND mode with no screen recognition description
// since we are not receiving, there's no need to specify received screen recognition descriptions
interactionSpec = new J2HODInteractionSpec();
interactionSpec.setExecutionTimeout(new Integer(60000));
interactionSpec.setInteractionVerb(new Integer(J2HODInteractionSpec.SYNC_SEND));
interactionSpec.setKeyName(J2HODInteractionSpec.ENTER);
interactionSpec.setScreenName("Logon Screen");
// Set Logoff Command - begin
out.println ("setting a Logoff Command to msgScreen - begin");
msgScreen.getField(2).setText("logoff"); //get and set command field
out.println ("setting a Logoff Command to msgScreen - done");
// Set Logoff Command - end
out.println ("trying execute with SYNC_SEND");
connection.execute(interactionSpec, msgScreen, null);
out.println ("successful execution of sending logoff command<br>");
// close interaction
out.println("trying interaction.close()...");
interaction.close();
out.println("interaction.close() successful.<br>");
// close connection
out.println("trying connection.close()...");
connection.close();
out.println("connection.close() successful.<br>");
} //try
catch (NamingException exn1)
{
out.println("***ERROR*** Operation failed: " + exn1 + "<br>");
exn1.printStackTrace();
}
catch (javax.resource.ResourceException exn2)
{
out.println("***ERROR*** Operation failed: " + exn2 + "<br>");
exn2.printStackTrace();
}
catch (com.ibm.connector2.screen.ScreenException se)
{
out.println ("***ERROR*** Operation failed: " + se.toString() + "<br>");
se.printStackTrace();
}
catch (Exception ex)
{
out.println("***ERROR*** Operation failed: " + ex + "<br>");
ex.printStackTrace();
}
catch (Throwable t)
{
out.println("***ERROR*** Operation failed: " + t.toString() + "<br>");
t.printStackTrace();
}
out.println ("<br>Main - Exit");
out.println ("</pre>");
%>
[ Top of Page | Previous Page | Next Page | Table of Contents ]