Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Applet servlet communication - Object serialization
- From: rgoy@xxxxxxx (Rahul Goyanka)
- Subject: Applet servlet communication - Object serialization
- Date: Fri, 29 Oct 1999 17:49:14 +0530
This is a multi-part message in MIME format.
------=_NextPart_000_0048_01BF2235.EA4E8A10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi=20
I m facing a problem in pushing a serialized object from servlet to =
applet.=20
Here is the servlet side code for POST request. I m trying to push a =
object of standard=20
java Integer class whose parent class implements serializable interface.
1.. public void doPost(HttpServletRequest request, HttpServletResponse =
res)
b.. throws IOException, ServletException
c.. {=20
d.. res.setContentType("application/octet-stream");
5.. Integer i =3D new Integer(10);
f.. outObj =3D new ObjectOutputStream(res.getOutputStream());
g.. outObj.writeObject(i);
h.. outObj.flush();
i.. outObj.close();
j.. }
The applet side code is as follows :
1.. public void init() {
b.. try{=20
c..=20
d.. mainSrvtURL =3D new URL(getCodeBase()+"servlet/MainServlet");
e.. srvtCnt =3D mainSrvtURL.openConnection();
f..=20
g.. srvtCnt.setDoInput(true);
h.. srvtCnt.setDoOutput(true);
i..=20
j.. srvtCnt.setUseCaches(false);
k.. srvtCnt.setDefaultUseCaches(false);
l..=20
m.. inObj =3D new ObjectInputStream(srvtCnt.getInputStream());
n..=20
o.. Object obj =3D inObj.readObject();
p.. Integer ger =3D (Integer) obj;
q.. inObj.close();
r.. }
s.. }
The error which i get in the loging which i m doing at the applet side =
is of the kinds that the Stream is corrupted
and the object is not a serializied object. Infact i tried with other =
objects of the standared classes in java which
implement serializable interface but for no help. I m feeling is that =
there is some problem in doing the Post request=20
by the applet iteslf. Could ne body help me with a suggestion what one =
exactly needs to do to serialize the object to
the applet with regard to this approach. I know of the other approches =
of RMI and CORBA . I want to find the error in this
approach only. Please suggest me ne side which implements the code like =
this.
Thanks in advance.
Rahul=20
goyanka@xxxxxxxxxxx
------=_NextPart_000_0048_01BF2235.EA4E8A10
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I m facing a problem in pushing a =
serialized object=20
from servlet to applet. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Here is the servlet side code for =
POST=20
request. I m trying to push a object of standard </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>java Integer class whose parent class =
implements=20
serializable interface.</FONT></DIV><FONT color=3D#000000 face=3Dcourier =
size=3D1>
<OL>
<LI></FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>public</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1> </FONT><FONT color=3D#c00000 =
face=3Dcourier=20
size=3D1>void</FONT><FONT color=3D#000000 face=3Dcourier size=3D1>=20
doPost(HttpServletRequest request, HttpServletResponse res)</LI>
<LI></FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>throws</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1> IOException, =
ServletException</LI>
<LI>{ </LI>
<LI>res.setContentType(</FONT><FONT color=3D#c10000 face=3Dcourier=20
size=3D1>"application/octet-stream"</FONT><FONT color=3D#000000 =
face=3Dcourier=20
size=3D1>);</FONT><FONT color=3D#000000 face=3Dcourier =
size=3D1></FONT></LI>
<LI><FONT color=3D#000000 face=3Dcourier size=3D1>Integer i =3D =
</FONT><FONT=20
color=3D#0000c0 face=3Dcourier size=3D1>new</FONT><FONT =
color=3D#000000 face=3Dcourier=20
size=3D1> Integer(</FONT><FONT color=3D#c20000 face=3Dcourier =
size=3D1>10</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1>);</LI>
<LI>outObj =3D </FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>new</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1>=20
ObjectOutputStream(res.getOutputStream());</LI>
<LI>outObj.writeObject(i);</LI>
<LI>outObj.flush();</LI>
<LI>outObj.close();</LI>
<LI>}</LI></OL>
<P><FONT face=3DArial size=3D2>The applet side code is as follows =
:</FONT></P><FONT=20
color=3D#000000 face=3Dcourier size=3D1>
<OL>
<LI></FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>public</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1> </FONT><FONT color=3D#c00000 =
face=3Dcourier=20
size=3D1>void</FONT><FONT color=3D#000000 face=3Dcourier size=3D1> =
init() {</LI>
<LI></FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>try</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1>{ </FONT></LI><FONT =
color=3D#000000=20
face=3Dcourier size=3D1><FONT color=3D#000000 face=3Dcourier =
size=3D1></FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1>
<LI></LI>
<LI>mainSrvtURL =3D </FONT><FONT color=3D#0000c0 face=3Dcourier=20
size=3D1>new</FONT><FONT color=3D#000000 face=3Dcourier size=3D1>=20
URL(getCodeBase()+</FONT><FONT color=3D#c10000 face=3Dcourier=20
size=3D1>"servlet/MainServlet"</FONT><FONT color=3D#000000 =
face=3Dcourier=20
size=3D1>);</LI></FONT><FONT color=3D#000000 face=3Dcourier size=3D1>
<LI>srvtCnt =3D mainSrvtURL.openConnection();</LI></FONT><FONT =
color=3D#000000=20
face=3Dcourier size=3D1>
<LI></LI></FONT><FONT color=3D#000000 face=3Dcourier size=3D1>
<LI>srvtCnt.setDoInput(</FONT><FONT color=3D#0000c0 face=3Dcourier=20
size=3D1>true</FONT><FONT color=3D#000000 face=3Dcourier =
size=3D1>);</LI>
<LI>srvtCnt.setDoOutput(</FONT><FONT color=3D#0000c0 face=3Dcourier=20
size=3D1>true</FONT><FONT color=3D#000000 face=3Dcourier =
size=3D1>);</LI>
<LI></LI>
<LI>srvtCnt.setUseCaches(</FONT><FONT color=3D#0000c0 face=3Dcourier=20
size=3D1>false</FONT><FONT color=3D#000000 face=3Dcourier =
size=3D1>);</LI>
<LI>srvtCnt.setDefaultUseCaches(</FONT><FONT color=3D#0000c0 =
face=3Dcourier=20
size=3D1>false</FONT><FONT color=3D#000000 face=3Dcourier =
size=3D1>);</LI>
<LI></LI></FONT><FONT color=3D#000000 face=3Dcourier size=3D1>
<LI>inObj =3D </FONT><FONT color=3D#0000c0 face=3Dcourier =
size=3D1>new</FONT><FONT=20
color=3D#000000 face=3Dcourier size=3D1>=20
ObjectInputStream(srvtCnt.getInputStream());</LI>
<LI></LI>
<LI>Object obj =3D inObj.readObject();</LI>
<LI>Integer ger =3D (Integer) obj;</LI></FONT><FONT color=3D#000000 =
face=3Dcourier=20
size=3D1>
<LI>inObj.close();</LI>
<LI>}</LI>
<LI>}</LI></OL>
<P></P>
<P></P></FONT><FONT size=3D2><FONT face=3DArial>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<OL></OL>
<DIV>The error which i get in the loging which i m doing at the applet =
side is=20
of the kinds that the Stream is corrupted</DIV>
<DIV>and the object is not a serializied object. Infact i tried with =
other=20
objects of the standared classes in java which</DIV>
<DIV>implement serializable interface but for no help. I m feeling is =
that there=20
is some problem in doing the Post request </DIV>
<DIV>by the applet iteslf. Could ne body help me with a suggestion what =
one=20
exactly needs to do to serialize the object to</DIV>
<DIV>the applet with regard to this approach. I know of the other =
approches of=20
RMI and CORBA . I want to find the error in this</DIV>
<DIV>approach only. Please suggest me ne side which implements the code =
like=20
this.</DIV>
<DIV> </DIV>
<DIV>Thanks in advance.</DIV>
<DIV> </DIV>
<DIV>Rahul </DIV>
<DIV> </DIV>
<DIV><A =
href=3D"mailto:goyanka@xxxxxxxxxxx">goyanka@xxxxxxxxxxx</A></DIV>
<DIV> </DIV>
<OL></FONT></FONT></FONT></OL></FONT></BODY></HTML>
------=_NextPart_000_0048_01BF2235.EA4E8A10--
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: MacOS & Multicast
- Next by Date: Calendar.get(Calendar.MONTH)
- Previous by thread: MacOS & Multicast
- Next by thread: Template
- Index(es):