I wrote an applet that communicates with a servlet, and they work just
fine, sending and receiving data, when I am testing them on my Win95 PC using
the JSDK WebServer (version 2.1).
I copied the class files to an AIX (version 4.2) server which has
Java runtime version 1.1.4. The applet seems to be able to
send data to the servlet, but an IOException <null> occurs when
the applet tries to receive data from the servlet (getInputStream
statement). The server is inside our corporate firewall.
The applet and servlet were developed using JDK version 1.1.8. I am
using Netscape browser 4.5 for both cases.
Whatsamaddah?
---------------------------------------------------------
Netscape's Java Console after execution (AIX 4.2):
---------------------------------------------------------
Netscape Communications Corporation -- Java 1.1.5
Type '?' for options.
Symantec Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation
# Applet debug level set to 9
java.io.IOException: <null>
at netscape.net.URLConnection.connect(Compiled Code)
* at netscape.net.URLConnection.getInputStream(Compiled Code)
at JAsrch01.doTheSearch(Compiled Code)
at JAsrch01.actionPerformed(Compiled Code)
at java.awt.Button.processActionEvent(Compiled Code)
at java.awt.Button.processEvent(Compiled Code)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)
--------------------------------------------------
Applet source code where the IOException occurred:
--------------------------------------------------
public void doTheSearch(String outputMessage)
throws IOException {
searchError = "NO";
String servletName = "../servlet/JSsrch01";
try {
getAppletContext().showStatus("Connecting");
URL theServletURL = new URL(getCodeBase(), servletName);
URLConnection con = theServletURL.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(4096);
DataOutputStream out = new DataOutputStream(byteOut);
getAppletContext().showStatus("Sending request");
out.writeUTF(outputMessage);
out.flush();
byte buf[] = byteOut.toByteArray();
con.setRequestProperty("Content-type",
"application/octet-stream");
con.setRequestProperty("Content-length",
"" + buf.length);
DataOutputStream dataOut =
new DataOutputStream(con.getOutputStream());
dataOut.write(buf);
dataOut.flush();
dataOut.close();
getAppletContext().showStatus("Searching...");
// end of send to server and beginning of read from server
getAppletContext().showStatus("Receiving results");
DataInputStream in =
new DataInputStream(con.getInputStream());
results = in.readUTF();
in.close();
} // end of try
catch (MalformedURLException ue) {
ue.printStackTrace();
searchError = "YES";
getAppletContext().showStatus(ue.toString());
} // end of catch MalformedURLException
catch (IOException ioe) {
ioe.printStackTrace();
searchError = "YES";
getAppletContext().showStatus(ioe.toString());
} // end of catch IOException
catch (Exception ex) {
ex.printStackTrace();
searchError = "YES";
getAppletContext().showStatus(ex.toString());
} // end of catch Exception
return;
} //end of doTheSearch method
--------------------------------------------------------------
Servlet source code (it does nothing except receive data from
the applet and send some test messages back to the applet).
--------------------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JSsrch01 extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
// Receive the data from the client (applet)
DataInputStream in =
new DataInputStream(request.getInputStream());
String stringValue = in.readUTF();
// System.out.println("Server received: " + stringValue);
// Send data to the client (applet)
String outputString = "TTTSMSGID" + "\t" +
"KEYWORDS" + "\t" +
"notes" + "\t" + "stuff" + "\t" +
"RESULTS" + "\t" +
"12345678" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes because" +
" it ain't working! It is always" +
" giving me problemsssssss" + "\t" +
"22222222" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"33333333" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"44444444" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"55555555" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"66666666" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"77777777" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"88888888" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"99999999" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t" +
"00000000" + "\t" + "0.713" + "\t" +
"reloaded Lotus Notes" + "\t" +
"WRKST" + "\t" + "2" + "\t" +
"503" + "\t" +
"Can't use Lotus Notes" + "\t";
response.setContentType("application/octet-stream");
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
out.writeUTF(outputString);
out.flush();
byte[] buf = byteOut.toByteArray();
response.setContentLength(buf.length);
ServletOutputStream servletOut = response.getOutputStream();
servletOut.write(buf);
servletOut.close();
// System.out.println("Server ended OK and sent: " + outputString);
} //end of service method
} //end of class
-----------------------------------------
JSDK WebServer messages (good execution):
-----------------------------------------
JSDK WebServer Version 2.1
Loaded configuration from: file:D:\jswdk1.0\jswdk-1.0\webserver.xml
endpoint created: localhost/127.0.0.1:8080
com.sun.web.core.DefaultServlet: init
com.sun.web.core.InvokerServlet: init
JSsrch01: init
----------------------------------------------------------------------
Netscape's Java Console after execution on JSDK WebServer(successful):
----------------------------------------------------------------------
Netscape Communications Corporation -- Java 1.1.5Type '?' for options.Symantec
Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html