A
Andrew Tucker
Hi everyone,
I am having real problems working out whats going on w/ my applet. I want to
be able to send an object from an applet to a servlet, here is the code for
the listener method causing the trouble:
private void addClientListener(java.awt.event.MouseEvent evt) {
System.out.println("Got this far, addClientListener.");
try {
URL fileURL = new URL(getDocumentBase(),
"servlet/MaintSchedServ");
URLConnection conn = fileURL.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("addClient", "true");
ObjectOutputStream out = new ObjectOutputStream(new
BufferedOutputStream(
conn.getOutputStream()));
out.writeObject(textField1.getText());
out.close();
} catch( Exception exc ) {
exc.printStackTrace();
}
}
I apologise if my usage of setRequestProperty is incorrect, i need to pass
several different objects to servlet and thought that by using this method
of URLConnection, i could evaluate this at servlet and handle each case
seperately. If there is a better way i would love to know how!
Here is the java console output, it is saying that i need to set doOutput =
true, well i am aren't I?
Thankyou in advance for any direction you can give me!!
Andrew.
Java(TM) Plug-in: Version 1.4.1_02
Using JRE version 1.4.1_02 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Andrew Tucker
/*
options
*/
Stopping applet ...
Unregistered modality listener
Joining applet thread ...
Destroying applet ...
Disposing applet ...
Joined applet thread ...
Quiting applet ...
Finding information ...
Releasing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=0
Caching classloader: sun.plugin.ClassLoaderInfo@4865ce
Current classloader cache size: 1
Done ...
Registered modality listener
Referencing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=1
Loading applet ...
Initializing applet ...
Starting applet ...
Got this far, addClientListener.
java.net.ProtocolException: cannot write to a URLConnection if
doOutput=false - call setDoOutput(true)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown
Source)
at AWTMaintSchedGUI.addClientListener(AWTMaintSchedGUI.java:114)
at AWTMaintSchedGUI.access$000(AWTMaintSchedGUI.java:17)
at AWTMaintSchedGUI$1.mouseClicked(AWTMaintSchedGUI.java:51)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I am having real problems working out whats going on w/ my applet. I want to
be able to send an object from an applet to a servlet, here is the code for
the listener method causing the trouble:
private void addClientListener(java.awt.event.MouseEvent evt) {
System.out.println("Got this far, addClientListener.");
try {
URL fileURL = new URL(getDocumentBase(),
"servlet/MaintSchedServ");
URLConnection conn = fileURL.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("addClient", "true");
ObjectOutputStream out = new ObjectOutputStream(new
BufferedOutputStream(
conn.getOutputStream()));
out.writeObject(textField1.getText());
out.close();
} catch( Exception exc ) {
exc.printStackTrace();
}
}
I apologise if my usage of setRequestProperty is incorrect, i need to pass
several different objects to servlet and thought that by using this method
of URLConnection, i could evaluate this at servlet and handle each case
seperately. If there is a better way i would love to know how!
Here is the java console output, it is saying that i need to set doOutput =
true, well i am aren't I?
Thankyou in advance for any direction you can give me!!
Andrew.
Java(TM) Plug-in: Version 1.4.1_02
Using JRE version 1.4.1_02 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Andrew Tucker
/*
options
*/
Stopping applet ...
Unregistered modality listener
Joining applet thread ...
Destroying applet ...
Disposing applet ...
Joined applet thread ...
Quiting applet ...
Finding information ...
Releasing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=0
Caching classloader: sun.plugin.ClassLoaderInfo@4865ce
Current classloader cache size: 1
Done ...
Registered modality listener
Referencing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=1
Loading applet ...
Initializing applet ...
Starting applet ...
Got this far, addClientListener.
java.net.ProtocolException: cannot write to a URLConnection if
doOutput=false - call setDoOutput(true)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown
Source)
at AWTMaintSchedGUI.addClientListener(AWTMaintSchedGUI.java:114)
at AWTMaintSchedGUI.access$000(AWTMaintSchedGUI.java:17)
at AWTMaintSchedGUI$1.mouseClicked(AWTMaintSchedGUI.java:51)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)