Well,
here is a reply to my own message :
I made some more tests and I found
out that if either of the 2 values passed to the Hashtable when instantiated
(start size and growth factor) is 0, then I get the exception I mentionned.
However, if both digits > 0, then everything works perfectly... There is
surely something I do not get here... I mean, these 2 digits are just there to
indicate the starting size of the table and the rate at which that table will
grow... this should not affect the way the thing is sent through the wire
!!!
-----Original Message-----
From: Maxime Poulin [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 31, 2000 2:38 PM
To: [EMAIL PROTECTED]
Subject: HashTable serialized ?????
From: Maxime Poulin [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 31, 2000 2:38 PM
To: [EMAIL PROTECTED]
Subject: HashTable serialized ?????
Hi all
!
I
have a strange problem here...
I
have an HttpServlet. This servlet receives request in its doGet method. If the
request has a specific parameter, I know I have to send the answer as a
serialized object. This is fairly simple :
public void
doGet(HttpServletRequest req, HttpServletResponse
res)
throws ServletException, IOException
{
// CHeck if the client wishes to receive the information using a socket.
if ("use_socket".equalsIgnoreCase(req.getParameter("format")))
{
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
throws ServletException, IOException
{
// CHeck if the client wishes to receive the information using a socket.
if ("use_socket".equalsIgnoreCase(req.getParameter("format")))
{
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
// out.writeObject(new
java.awt.Rectangle(1,2,3,4));
Hashtable hTable = new
Hashtable(0,1);
hTable.put("1", "Premiere chaine");
hTable.put("2", "Seconde chaine");
out.writeObject(hTable);
}
else
{
res.setContentType("text/html");
PrintWriter out = new PrintWriter (res.getOutputStream());
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("Dynamically generated by servlet.");
out.println("</body></html>");
out.close();
}
}
hTable.put("1", "Premiere chaine");
hTable.put("2", "Seconde chaine");
out.writeObject(hTable);
}
else
{
res.setContentType("text/html");
PrintWriter out = new PrintWriter (res.getOutputStream());
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("Dynamically generated by servlet.");
out.println("</body></html>");
out.close();
}
}
And then I have this applet
which sends the request and reads the answer as :
try
{
URL url = new URL(getCodeBase() + "servlet/Servlet1");
String params = "?format=use_socket";
url = new URL(url.toExternalForm() + params);
myTextArea.append("\nOpening " + url);
{
URL url = new URL(getCodeBase() + "servlet/Servlet1");
String params = "?format=use_socket";
url = new URL(url.toExternalForm() + params);
myTextArea.append("\nOpening " + url);
URLConnection con =
url.openConnection();
con.setUseCaches(false);
con.setUseCaches(false);
ObjectInputStream input = new
ObjectInputStream(con.getInputStream());
Object obj = input.readObject();
myTextArea.append("\nReading answer.");
myTextArea.append("\n" + obj.toString());
Object obj = input.readObject();
myTextArea.append("\nReading answer.");
myTextArea.append("\n" + obj.toString());
..............
}
catch(Exception e)
{
}
As you can see, this is very very simple. I tried with a Date object and it
works perfectly. I also tried with a java.awt.Rectangle and it also works
perfectly. However, when I try with a Hashtable, I get an exception quite
strange :
--
java.io.FileNotFoundException:
localhost:80//servlet/Servlet1?format=use_socket
--
What does this means ? I can't use Hashtable ? It does implement Serializable so
where is the problem ? If the same code works for a Rectangle or a Date, I can
hardly see why it won't work with a Hashtable ???
Any idea
?
Maxime.
