i believe you have to allocate your Stings when you're adding them to
the hash table, don't you?  i.e.:
hTable.put(new String("1"), new String("Premiere chaine"));

i've been doing this and haven't had any problems (yet) with hash
tables.  if this is incorrect please, someone, let me know.
..............ron.

> Maxime Poulin wrote:
>
> 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());
> //      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();
>     }
>   }
>     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);
>
>             URLConnection con = url.openConnection();
>             con.setUseCaches(false);
>
>             ObjectInputStream input = new
> ObjectInputStream(con.getInputStream());
>             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.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to