wood burning stoves 2.0*
The moose likes Applets and the fly likes problem in applet-servlet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "problem in applet-servlet communication" Watch "problem in applet-servlet communication" New topic
Author

problem in applet-servlet communication

John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
hello friends,
now i am going to describe the problem i am phasing

actually i have embedded japplets in a jsp page(appletjsp) and want to communicate japplets indeed jsp to a servlet in the diffrent derectory but in same context root.
moreover, i have written code at applet and servlet side both. actually there is a next button in one of japplets(embedded in appletjsp) and i have written the code(for servlet communication) inside button's mouse clicked event. and at servlet side, as usual i have got an inputstream from request and want to forward this request(after getting request dispatcher) to another jsp page. actually i am proposing to run this jsp page after clicking next button from appletjsp .

now the problem that made me a bit confused is that when i click next button after running jsp page(containing japplets) then neither there is any error/exception at server/IE's sun java console nor any effect of code at servlet side.

actually i am not sure that the servlet side code does not make any effect rather it is ony my assumption.

although i am very new in java and as what i know, to send back response to client side, servlet class needs to be run at server side and probabbly for that there must be a sepreat request from client's applet to server(please dont flame me if i am wrong).

so please tell me how can i get another jsp page(to which i trying to get request dispatcher)running after clicking next button?

applet code:




servlet code:





although this topic has been made too long, even then please fix my problem.

thanks
John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
my above problem ha been solved, i given response to applet and retrieved it at applet side through ObjectInputStream. and now it is working.

but why it was not working before? is it must to open InputStream at applet side to retrieve data, sent back by servlet as response?

one more thing
my intention is to
1) user enter data in an applet which is embedded in jsp then
2) click submit and send it to a servlet then
3) forward those to another jsp page.



but with this i am getting java.io.streamCurrupted Exception at sun java console in the line where i tried to get ObjectInputStream in applet side to retrieve data back that is sent from servlet.


please make a quick response to solve this problem
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
The code performs a RequestDispatcher.forward, and afterwards does something with the output stream - that won't work. You can only do one of these things, not both - either forward the request, or handle it by writing to the output stream.


Ping & DNS - my free Android networking tools app
John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
probabbly you are suggesting as what i got is that i should open an ouputstream to communicate to target jsp.
if it seems to be possible like applet servlet communication then i will try it.

thanks a lot
John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
hello friends one second,

i have tried whatever i wants by,

1) sending data by post method from applet to servlet then
2) storing those in a bean in session scope(to retrieve back from target jsp in the same session) then
3)as Mr Ulf said above that at servlet side i can use only one(either forward or write to ObjectOutputStream) therefore i wrote to outputstream and read it back from applet then

servlet side:



3) from the same applet after reading data i tried to open target jsp using appletcontext.showdocument method then

applet side:

4)in target jsp i intantiated the bean in which i had stored all data from servlet, in the same session scope.

Editpage.jsp:



but when i tried to get the properties value then i got following exception at server side



here sfirst_name is a property field.


if i am going right on my stupid way, then please tell me how can i display all the datas back as feedback on a target jsp?

[ November 20, 2007: Message edited by: John Mclain ]
[ November 20, 2007: Message edited by: John Mclain ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
probabbly you are suggesting as what i got is that i should open an ouputstream to communicate to target jsp.

Using streams from within a JSP page will not work. JSPs are for generating text, not binary data; you'll need to do this from within a servlet.
John Mclain
Ranch Hand

Joined: Nov 04, 2007
Posts: 30
thanks Mr Ulf, i got it

i am not doing so what you are prohibiting for. i used a dirrent approach instead. and that i have explained already in my previous reply.

please take a look over there and catch how much i am right on my way?
Santhosh Yanala
Greenhorn

Joined: Jan 25, 2014
Posts: 2
Hi, i am new to this forum.

fist of all thanks to "John Mclain" for providing a long discussion with Applet

Recently i started to work with applet.

I have problem in applets. i.e


1. My first Request started from .jsp page which is embedded with Applet
2. My Applet internally write the output stream object for some other JSP
3. My Applet internally calls the That Target JSP and loaded the output stream object in Target jsp page(i.e holds the object in session variable)

Up to now it is working fine. But my problem is , i need to skip from Applet. i dont want to stay at Applet any more, because i need to display one more JSP page which was displayed the values obtained from Applet.

Please any one help me...Thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Welcome to JavaRanch. From within the applet, you can go to a different page using the AppletContext's showDocument method.
Santhosh Yanala
Greenhorn

Joined: Jan 25, 2014
Posts: 2
Thanks you so much..."Ulf Dittmer"


Now its working....
 
jQuery in Action, 2nd edition
 
subject: problem in applet-servlet communication