• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a Servlet from an applet

 
Kiran H Iyer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kiran H Iyer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic