Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

servler does not read two strings.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic