Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.lang.IllegalStateException:Already Connected

843841Jan 2 2005 — edited Aug 22 2006
HI everyine,
I trying to send some data from an applet to a servlet: Here is code for the applet:
try{
	System.out.println("in the try for getData \n");
	URL url = new URL("http://myip/app/servlet/getData");
 	System.out.println("the url connection to getData done \n");

    URLConnection servletConnection2 =url.openConnection();
    ///////////////I get  error java.lang.IllegalStateException:Already Connected  at this point //////
    servletConnection2.setDoInput(false);
    servletConnection2.setDoOutput(true);
   servletConnection2.setUseCaches (false);
   servletConnection2.setDefaultUseCaches (false);
   servletConnection2.connect();
  servletConnection2.setRequestProperty("Content-Type","application/octet-stream");

ObjectOutputStream oos = new ObjectOutputStream(servletConnection2.getOutputStream());
	oos.writeObject(userID);
	oos.flush();
	System.out.println("the userID was flushed");
	oos.close();
}
catch(Exception e)
{
	System.out.println("Error in sending data to getData Servlet \n" +e);
}
Here is what I have in my servlet:
public class getData extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
                        String username ="";
	try
	{
   ObjectInputStream in = new ObjectInputStream(request.getInputStream());
     username = (String)in.readObject();
     System.out.println("the username received from ui is \n" +username);
     in.close();
 }
 catch (IOException e)
  {
System.out.println("error1" + e);
}
catch (ClassNotFoundException cnfe)
{								{System.out.println("error2");
}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {

                     doGet(request,response);

	        }
}
When I try to access this applet I keep getting an error :
java.lang.IllegalStateException: Already connected
I cannot understand why this could eb happening ..I have been stuck on this problem for quite some time now.....
Thanks,
G.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2006
Added on Jan 2 2005
7 comments
6,532 views