Hi,
I have the following java class running in an ASP/VB browser
application. Its intended to dynamically fetch menu information from a
database and display results in a tree view style in the client's browser.
It's used so as to avoid refreshing the whole page. However, it only works
when the app is installed on a machine with a Microsoft VM. It doesnt appear
to be properly Sun/Java complient - something to do with I/O streams
perhaps? Can someone help solve this for me please as its currently beyond
my Java ability. Look forward to any replies. Thanks!

Chris.

*****************************
import java.applet.Applet;
import java.io.*;
import java.net.*;
//import com.ms.security.*;

public class TP_Return extends Applet
{

String mSessionID;
String mTargetASP;

public void stop()
{
mSessionID = "";
mTargetASP = "";
}

public void destroy()
{
}

public String ioRoutine(String ioCommandType, String ioDataParam)
{
URL aspTargetURL = null;
URLConnection ioConnection = null;
DataInputStream iStream = null;
DataOutputStream oStream = null;
int bytes_read = 0;
byte buffer[] = new byte[1024];
String ioDataString = "";

if (mTargetASP == null)
{mTargetASP = ioDataParam;}

try
{aspTargetURL = new URL(mTargetASP);}
catch(MalformedURLException err)
{System.out.println("Unable to create URL for CGI ("
+ mTargetASP + "): " + err);}

try
{ioConnection = aspTargetURL.openConnection();}
catch(IOException err)
{System.out.println("Unable to open URL connection:
" + err);}

// May be needed
//PolicyEngine.assertPermission(PermissionID.NETIO);
ioConnection.setDoOutput(true);
ioConnection.setDoInput(true);
ioConnection.setUseCaches(false);
ioConnection.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
ioConnection.setAllowUserInteraction(false);

try
{oStream = new
DataOutputStream(ioConnection.getOutputStream());}
catch(IOException err)
{System.out.println("Unable to create the output
stream: " + err);}
catch(SecurityException err)
{System.out.println("SecurityException : " + err);}

int intNoCase = ioCommandType.indexOf("NoCaseChange");
if (intNoCase == -1)
{ioCommandType = ioCommandType.toUpperCase();}
String ioInformation = "";
// If ioCommandType is "getparam" ioInformation will look
like this:
//
"command=getparam&version=2.0&session_id=TPRO001&aicc_data="
// If ioCommandType is "putparam" ioInformation will look
like this:
//
"command=putparam&version=2.0&session_id=TPRO001&aicc_data=[core]\r\nlesson_
status=I\r\nscore=30\r\ntime=00:00:2000\r\n[Progress]\r\np_fnumber=12";

// If ioCommandType is "putTPInfo" ioInformation will look
like this:
//
"command=putTPInfo&TPSkill_ID=56&TP_Perc=14&TP_FN=12&TP_Time=135";
int pos = ioCommandType.indexOf("TPINFO");
if (pos != -1)
{
pos = ioCommandType.indexOf("~");
if (pos != -1)
{
String lngFIID = ioCommandType.substring(pos
+ 1);
ioInformation = "command=GETFIINFO&FIIndex="
+ lngFIID;
}
else
{ioInformation = "command=" + ioCommandType
+ "&" + ioDataParam;}
}
else
{
if (mSessionID == null)
{mSessionID = "-1";}
ioInformation = "command=" + ioCommandType +
"&version=2.0" + "&session_id=" + URLEncoder.encode(mSessionID) +
"&aicc_data=" + URLEncoder.encode(ioDataParam);

}

try
{
oStream.writeBytes(ioInformation);
oStream.flush();
oStream.close();
}
catch(IOException err)
{System.out.println("Unable to write the data: " +
err);}

try
{iStream = new
DataInputStream(ioConnection.getInputStream());}
catch(IOException err)
{System.out.println("Unable to open HTTP connection
to read: " + err);}

try
{
while((bytes_read = iStream.read(buffer)) > 0)
ioDataString += new String(buffer, 0, 0,
bytes_read);
}
catch(IOException err)
{System.out.println("Unable to read POST response: "
+ err);}

finally
{
try
{
if(iStream != null)
iStream.close();
}
catch(IOException err)
{System.out.println("Unable to close HTTP
connection: " + err);}
}

return ioDataString;
}

public void init()
{
URL urlString = getDocumentBase();
String fileName = urlString.getFile();
String upperFileName = fileName.toUpperCase();
// Get AICC ID Number and store in mSessionID variable
int pos = upperFileName.indexOf("AICC_SID");
if(pos > -1)
{
mSessionID = fileName.substring(pos + 9);
if(mSessionID.indexOf("&") > -1)
{mSessionID = mSessionID.substring(0,
mSessionID.indexOf("&"));}
}

// Get Callback ASP Page and store in mTargetASP
pos = upperFileName.indexOf("AICC_URL");
if(pos > -1)
{
mTargetASP = fileName.substring(pos + 9);
if(mTargetASP.indexOf("&") > -1)
{mTargetASP = mTargetASP.substring(0,
mTargetASP.indexOf("&"));}
}

// I think this bit is URLUnencoding the Target ASP Path
String temp = new String("");
for(int i = 0; i < mTargetASP.length(); i++)
{
if(mTargetASP.charAt(i) == '+')
{temp += 32;}
else
{
if(mTargetASP.charAt(i) == '%')
{
int lead = mTargetASP.charAt(i + 1);
if(lead < 65)
{lead -= 48;}
else
{
if(lead < 80)
{lead -= 65;}
else
{lead -= 97;}
}
int trail = mTargetASP.charAt(i +
2);
if(trail < 65)
{trail -= 48;}
else
{
if(trail < 80)
{trail -= 55;}
else
{trail -= 87;}
}
temp += (char)(lead * 16 + trail);
i += 2;
}
else
{temp += mTargetASP.charAt(i);}
}
}
mTargetASP = temp;
}
}