Get rid of
>> res.setContentType("applic
>>
Vector emp = new Vector();
emp.add(0,new String("he"));
emp.add(1,new String("she"));
>>
can be
Vector emp = new Vector();
emp.add("he");
emp.add("she");
Main Topics
Browse All TopicsHello to all Experts.
I have a java swing Gui giving the servlet a parameter:
--------------------------
String empId="rom01";
ObjectOutputStream output = new ObjectOutputStream(servlet
output.writeObject(new String(empId));
--------------------------
The servlet gets the input:
//open InputStream
ObjectInputStream input=new ObjectInputStream(req.getI
String empId=(String)input.readOb
--------------------------
//servlet doGet method opens OutputStream
ObjectOutputStream output=new ObjectOutputStream(res.get
// Set the contenty type to application/octet-stream
res.setContentType("applic
Vector emp = new Vector();
emp.add(0,new String("he"));
emp.add(1,new String("she"));
output.writeObject(emp);
--------------------------
When I call the method which in turns communicates with the servlet I get this error message:
exception
java.io.EOFException
java.io.ObjectInputStream$
java.io.ObjectInputStream$
...
--------------------------
also the application servers gives this exception message:
java.lang.NullPointerExcep
at java.lang.String.<init>(St
at TableTest.doGet(TableTest.
at TableTest.doPost(TableTest
--------------------------
I have left out try and catch blocks in order not to clutter the message.
What do you think is the problem with this code ?
Thanks
Mimo
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hello,
I tried the suggestion of CEHJ but I got the same Exception message.
Here is the full code as OBJECTS asked for:
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOExcepti
//open InputStream
ObjectInputStream input=new ObjectInputStream(req.getI
// open OutputStream
ObjectOutputStream output=new ObjectOutputStream(res.get
try {
// read the employee id sent by the apple
String empId=(String)input.readOb
// Set the contenty type to application/octet-stream
res.setContentType("applic
// getConnection method returns a
// connection to the Employee database
Connection con=getConnection();
Vector emp = new Vector();
if(con != null) {
String[] empDetails = fetchDetails(con,empId.toS
emp.add(0, new String(empDetails[0]));
emp.add(1, new String(empDetails[1]));
} else {
// Connection was not successful, return proper messages
emp.add(0, new String("Could not establish"));
emp.add(0, new String("connection to database"));
}
// Close the connection
try {
con.close();
} catch(SQLException se) {
System.out.println("error 1");
se.printStackTrace();
}
// Send data
output.writeObject(emp);
} catch(Exception e) {
System.out.println(e.getMe
System.out.println("error 2");
e.printStackTrace();
}
// flush the output and close
output.flush();
output.close();
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOExcepti
doGet(req,res);
}
--------------------------
I have avoided the use of ObjectInputStream input in order to make the scenario simplier.
private void searchTest() {
// get the employee id keyed in
String empId="rom01";
try {
// Initialize URL to call the servlet
URL url=new URL("http://localhost:8084
// Open the connection to servlet.
URLConnection servletConnection = url.openConnection();
//System.out.println("Poin
// Set client caching to false
servletConnection.setUseCa
// Enable I/O through the connection
servletConnection.setDoInp
servletConnection.setDoOut
// set request content type to object type
servletConnection.setReque
// gets the InputStream on the servlet and send employee
//id to the servlet
ObjectOutputStream output = new ObjectOutputStream(servlet
// Pass the employee ID
output.writeObject(new String(empId));
// flush and close the output
output.flush();
output.close();
// get the InputStream from the servlet and read the
//Employee object
InputStream input = servletConnection.getInput
ObjectInputStream ois = new ObjectInputStream(input);
// Get the employee object
Vector emp=(Vector)ois.readObject
ois.close();
// Get the details
String name=(String) emp.elementAt(0);
String city=(String) emp.elementAt(1);
// set the values read into the text boxes
jTableStyle.setValueAt(nam
jTableStyle.setValueAt(cit
//System.out.println("Fini
} catch(Exception e) {
// Exception occured during search
e.printStackTrace();
// Display message in text boxes
board.setText("other Exception");
}
}
--------------------------
I do get error message no 2 at line
System.out.println("error 2");
Thanks
Mimo
Business Accounts
Answer for Membership
by: objectsPosted on 2006-01-27 at 23:13:26ID: 15811286
looks like the server is trying to create a string with null, so the connection is getting closed
can you post all the code for send/recieving on the stream at bvoth ends.