aspose file tools*
The moose likes Applets and the fly likes Applet Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Servlet Communication" Watch "Applet Servlet Communication" New topic
Author

Applet Servlet Communication

hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
Can you please help me out in this issue.


Our requirement is that Applet (PrintApplet in our case)just needs to send a value(jsp page name)
to a servlet(AppletListenerServlet in our case) and that servlet needs to redirect it to the page which is sent by the Applet.

My applet request is able to reach the servlet and i am able to get the jsp page value in the servlet,but the servlet is not able to forward the request to that jsp instead of that the same applet page is displayed.

Servlet is not able to forward the request.

Could you please please please help me out in this ....

Many many thanks in advance.


hareesh Puthala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42916
    
  68
So the applet calls the servlet using java.net.URLConnection or something similar? If so, then the servlet can't cause the applet page to redirect to another page - the applet needs to do that by calling AppletContext.showDocument.
hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
Ulf Dittmer wrote:So the applet calls the servlet using java.net.URLConnection or something similar? If so, then the servlet can't cause the applet page to redirect to another page - the applet needs to do that by calling AppletContext.showDocument.



Iam getting this Exception while iam trying to call the method 'this.getAppletContext().showDocument(url)';


Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at sun.plugin2.main.client.MessagePassingExecutionContext.showDocument(Unknown Source)
at sun.plugin2.main.client.MessagePassingExecutionContext.showDocument(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletContextImpl.showDocument(Unknown Source)
at PrintApplet.actionPerformed(PrintApplet.java:105)
at java.awt.Button.processActionEvent(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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)

But the appletcontext object is not null which i found on the java console.

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42916
    
  68
The NPE occurs in the showDocument method, so the AppletContext is obviously not null.

What's the value of the URL you're passing in? In which browser does this happen?
hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
Ulf Dittmer wrote:The NPE occurs in the showDocument method, so the AppletContext is obviously not null.

What's the value of the URL you're passing in? In which browser does this happen?



Value of the URL is: http://10.16.1.43:8090/collectionpak/pages/consumerService.jsp

And the browser is IE 6.0
hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
hareesh Puthala wrote:
Ulf Dittmer wrote:The NPE occurs in the showDocument method, so the AppletContext is obviously not null.

What's the value of the URL you're passing in? In which browser does this happen?



Value of the URL is: http://10.16.1.43:8090/collectionpak/pages/consumerService.jsp

And the browser is IE 6.0



Here is my code:

I am performing spme business logic in the create method(It creates a text file in the local file system and drives the default printer and prin ts the text file.)


Please look into this ...
Thanks a lot for helping me.
hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
Now it is not even calling the appletcontext.showDocument().

Why this is happening?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42916
    
  68
This is never a good idea:

You need to do proper error handling. At least put something like "e.printStackTrace()" so that you know what happened.

Also, does "urlstr" have any meaning? It is not used in the code.
hareesh Puthala
Greenhorn

Joined: Jan 11, 2010
Posts: 21
Thanks a lot Ulf Dittmer..

It has done the trick.

Once again thank you very much......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet Servlet Communication