Applet/Servlet Communication 1.4

S

shahram

Hi,

I have a problem with Applet/Servlet Communication after upgrading
from 1.3.1 to 1.4.X. My program use to work perfect with 1.3.1 and
with 1.4 it does not
create any Exception and Servlet does not get called.

server environment (jakarta-tomcat-4.0.1)

Any help would be appreciated.


Thanks
Shahram...
 
A

Andrew Thompson

S

shahram

Ike said:
Post us some code so we can see what your problem is!
-Ike

Thanks for response, here I have a simple code for you I hope you are
gonna be able to catch the bug or find the issue.


// this ia a method of applet sendin the data (String) to servlet.
public void sendData () {
try {
// the following servlet is mapped on the server in
TomCat.
URL url = new
URL("http://localhost:8080/myServlet?p1=abc&p2=def&p3=ghi");
URLConnection urlCon = url.openConnection();

// inform the connection that we will send output and
accept input
urlCon.setDoInput(true);
urlCon.setDoOutput(true);

// Don't use a cached version of URL connection.
urlCon.setUseCaches(false);
urlCon.setDefaultUseCaches(false);

// Specify the content type that we will send binary data
urlCon.setRequestProperty("Content-Type",
"application/octet-stream");

// sending the data
ObjectOutputStream outputToServlet = new
ObjectOutputStream(urlCon.getOutputStream());
outputToServlet.writeObject("This is a primitve
serializable object (String)");
outputToServlet.flush();
outputToServlet.close();

} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex1) {
ex1.printStackTrace();
}
}



this the servlet very simple
class myServlet extends HttpServlet {

public void doGet (HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException {

doPost(request, response);
}

public void doPost (HttpServletRequest request,
HttpServletResponse response) throws
ServletException,
IOException {


try {
// get an input stream from the applet
ObjectInputStream inputFromApplet = new
ObjectInputStream(request.getInputStream());

// read the serialized data from applet
String str = (String) inputFromApplet.readObject();
inputFromApplet.close();
// out put to console
System.out.println("DEBUG: " + str);
// out put to tomcat log
log("DEBUG: " + str);

} catch (IOException IOe) {
System.out.println("DEBUG: doPost()" +
IOe.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("DEBUG: doPost()" +
ex.getMessage());
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top