HI,
I have an
applet through which I am trying to pass two strings to a
servlet using writeObject (URLCOnnection). If there is only one
string the servlet works fine but as soon as I add the code for reading the second incoming stream it gives me an error as:
error in reading string useridjava.io.EOFException
Heres what I am actually doing:
try{
String servletStr = "http://localhost:8080/IOC/servlet/senddata";
URL url = new URL(servletStr);
HttpURLConnection servletConnection2 = (HttpURLConnection)(url).openConnection();
System.out.println("the urlconn to getData was established");
servletConnection2.setDoInput(true);
servletConnection2.setDoOutput(true);
servletConnection2.setRequestMethod("POST");
servletConnection2.setUseCaches (false);
System.out.println("UseCaches");
servletConnection2.setDefaultUseCaches (false);
servletConnection2.setRequestProperty("Content-Type","application/octet-stream");
oos= new ObjectOutputStream(servletConnection2.getOutputStream());
oos.writeObject(userID);
oos.flush();
System.out.println("the userID flushed was " +userID);
InputStream in = servletConnection2.getInputStream();in.close();
}catch(Exception e){
System.out.println("Error in sending data to senddata Servlet \n" +ex);
}
After this part of code I have some code to select a node from a JTRee. and I want to send the node's value to the servlet.
Heres the code for that part:
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if(node==null)
return;
Object nodeInfo = node.getUserObject();
uName = tree.getLastSelectedPathComponent().toString();
System.out.println("the uName is" +uName);
if (node.isLeaf()) {
try
{
oos.writeObject(uName);
oos.flush();
System.out.println("the socket is " +uName);
oos.close();
}
catch(Exception ex2){
System.out.println("error in sending uName \n");
}
However when I try to read the string sent from the applet as follows I get an EOFException.
try{
InputStream in=req.getInputStream();
ObjectInputStream ois= new ObjectInputStream(in);
userID=ois.readObject().toString();
uName=ois.readObject().toString();
in.close();
}
catch(Exception e)
{
System.out.println("error in reading string userid" +e);
}
Can somebody tell me how to get around this.
I have tried changing the position of the code (to after the node selection) so thast instead of sending data to servlet twice it can be done
once but I get the same error.
Any help would be appreciated.
Thanks,
G.