aspose file tools*
The moose likes Applets and the fly likes How to call a Servlet from an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "How to call a Servlet from an applet" Watch "How to call a Servlet from an applet" New topic
Author

How to call a Servlet from an applet

Kiran H Iyer
Greenhorn

Joined: Dec 03, 2001
Posts: 11
hello
I have an applet, which contains a Button, on clicking that button I have to call an JSP page, which is in another m/c.I am viewing the applet via appletviewer, and I have to call it only through appletviewer because my other application is running via that.I am able to call the JSP page when I viewed the applet through IE.
Kindly help me to come out from this
Thanking you
regards
Kiran
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

An applet can invoke a servlet, JSP, or even non-Java items like ASPs and CGIs by creating an HttpURLConnection. This works whether you're running in AppletViewer or in a browser (although browsers are limited to contacting the same server that the applet came from).
When you say "call" a JSP page, I'm assuming you mean to retrieve data, rather than to cause a new web page to be displayed somewhere. That's a different matter.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kiran H Iyer
Greenhorn

Joined: Dec 03, 2001
Posts: 11
hello Tim,
Pls advice me how to use the HttpUrlConnection class inside a applet as it is declared abstract.
pls help me with some codes.
thanks a lot
regards
Kiran
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

I wish I had some code to show you, but it's sitting on a machine at my ex-employer. I recommend you grab a book on Java network programming, since it's what I'd have to do myself.
The way to get an HttpURLConnection is simply to define a URL object and use its openConnection() method. If the URL object refers to an http URL, like:
URL javaRanch = new URL("http://www.javaranch.com/cgi-bin/search?find=mongoose");
do:
HttpURLConnection javaRanchLink = (HttpURLConnection) javaRanch.openConnection();
The JavaDocs for HttpURLConnection's parent class have some useful info on them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a Servlet from an applet