Hi everybody
I�m having a problem with the communication between an applet
and a servlet using the netscape enterprise server 4.0 SP2 (the iplanet web
server).
If the applet just listen to the servlet it works fine ( the doget methot
responds ok), but if the applet send a few bytes (a String) to the servlet
using the post method
and then the servlet responds with "I receive the message", the applets hungs
up throwing an
IOException.
The exception it throws is :
IOException: webserver:80//servlet/HappyServlet
The example works fine with the httpd that comes with the sun�s
jsdk but not with the Iplanet.
Does anybody know what is the problem?
Thanks,
Fernando.
the code seems like this:
///////////////////////////// SERVLET /////////////////////////////
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.* ;
public class MyServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
try {
// read the data from applet
BufferedReader dis
= new BufferedReader(new
InputStreamReader(req.getInputStream()));
String reqData = "" ;
String s = "" ;
while ( ( s = dis.readLine() ) != null ) {
reqData = reqData + "\n" + s ;
}
dis.close() ;
// send new data to applet
PrintWriter out = resp.getWriter() ;
// This is where the communication fails.
// I think it keeps trying to send the message
// for a few seconds and then fails with an exception IOException.
out.println("This is the message to send.");
out.close() ;
}
catch (Exception e) {
throw new ServletException(e.toString());
}
return;
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException
{
doPost(req, resp);
}
}
///////////////////////////// APPLET /////////////////////////////
import java.applet.*;
import java.net.*;
import java.io.*;
public class MyApplet extends Applet
{
public void init()
{
}
public void start()
{
String ms = connectToServlet( "http://webserver:80//servlet/MyServlet",
"Message from applet." ) ;
}
protected void connectToServletEx( String anURL, String aMessage ) {
try {
URL url = new URL( anURL );
try {
// Create connection
URLConnection conn = url.openConnection();
conn.setDoOutput( true );
conn.setRequestProperty( "Content-Type",
"application/x-www-form-urlencoded" );
// send data to servlet
PrintStream outStream = new PrintStream( conn.getOutputStream()
);
outStream.print( aMessage );
outStream.close();
// read data from servlet
DataInputStream in = new DataInputStream( conn.getInputStream()
);
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (IOException e) { e.printStackTrace(); }
} catch (MalformedURLException e) { e.printStackTrace(); }
return null ;
}
}
//////////////////////////////////////////////////////////
___________________________________________________________________________
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