How can I send an object with Header from an Applet???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Florian_Binder
Posted On:   Tuesday, July 10, 2001 09:32 AM

Hi, I want to send an object from my applet to my servlet, but I need to set a Header, because the servlet needs it to know what kind of object it receives. Here is my source-code: from my Applet: int port = 8080; try { java.net.URL currentPage = applet.getCodeBase(); String protocol = currentPage.getProtocol(); String host = currentPage.getHost(); port = currentPage.getPort(); } catch(java.lang.NullPointerException evt) { } port = 8080; String urlSuffix = "/abrechnung/servlet/Daten"; java.net.URL dataURL = new java.net.URL("http://localhost:8080"+urlSuffix); ja   More>>

Hi,


I want to send an object from my applet to my servlet, but I need to set a Header, because the servlet needs it to know what kind of object it receives.


Here is my source-code:


from my Applet:


			

int port = 8080;
try {
java.net.URL currentPage = applet.getCodeBase();
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
port = currentPage.getPort();
} catch(java.lang.NullPointerException evt) {
}
port = 8080;
String urlSuffix = "/abrechnung/servlet/Daten";
java.net.URL dataURL = new java.net.URL("http://localhost:8080"+urlSuffix);
java.net.URLConnection connection = dataURL.openConnection();
connection.setUseCaches(false);
connection.setDoOutput(true);
java.io.ByteArrayOutputStream byteStream = new java.io.ByteArrayOutputStream(512);
java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(connection.getOutputStream());

out.writeObject(this.getKunde());
out.flush();

connection.setRequestProperty("cmd", "updatekunden"); // This is line 197 in save()
connection.setRequestProperty("Content-Length", String.valueOf(byteStream.size()));
connection.setRequestProperty("Content-Type", "application/x-www-serialized-object");

byteStream.writeTo(connection.getOutputStream());

from my Servlet:
			
action = request.getHeader("cmd");
System.out.println(action);

if(action.equals("getkunde")) {
getKunde();
} else if(action.equals("getkunden")) {
getKunden();
} else if(action.equals("getserver")) {
getServer();
} else if (action.equals("updatekunden")) {
updateKunden();
}


But this doesn't work. This is the Error:

			
Java(TM) Plug-In: Version 1.3.0_01
Verwendung der JRE-Version 1.3.0_01 Java HotSpot(TM) Client VM

Exception occurred during event dispatching:
java.lang.IllegalAccessError: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:822)
at Server.Panels.Daten.save(Daten.java:179)
at Server.Panels.Daten.editsave(Daten.java:253)
at Server.Panels.Daten.access$0(Daten.java:242)
at Server.Panels.Daten$1.actionPerformed(Daten.java:229)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3717)
at java.awt.Component.processEvent(Component.java:3546)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:333)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
   <<Less

Re: How can I send an object with Header from an Applet???

Posted By:   John_Zukowski  
Posted On:   Wednesday, July 11, 2001 10:39 AM

It is amazing what you find if you look in the FAQ first: What content type do I use when writing an object ...
About | Sitemap | Contact