How do you push an applet in to the servlet?

Showing Answers 1 - 8 of 8 Answers

subbareddy

  • Apr 6th, 2006
 

give me soluetion

  Was this answer useful?  Yes

bhaskar

  • Apr 6th, 2006
 

how do you push an applet in to the servlet?

  Was this answer useful?  Yes

aditya

  • Apr 7th, 2006
 

Hi,

To make the applet talk to the servlet you need to use HttpURLConnection.

Open a URLConnection from an apple to the sevlet by using the url path of the servlet in the applet.

Then use InputStreams to the servlet and write you data to the servlet using either DataInputStream or Obejct InputStreams. You need to tell the servlets about the content type you are sending to the servlets using your DatainputStream or ObjectInputStream.

In servlets you use request objec to read the contents from the applet.

Hope this answers your question.

  Was this answer useful?  Yes

sbarik

  • Apr 10th, 2006
 

If u want to communicate between Applet and servlet(Means calling a Servlet from Applet) then U can do like this


I am giving u a simple example for opening a connection With servlet from Applet-

private URLConnection getServletConnection()
  throws MalformedURLException, IOException {

   URL urlServlet = new URL(getCodeBase(), "echo.class");

 URLConnection con = urlServlet.openConnection();

   con.setDoInput(true);
  con.setDoOutput(true);
  con.setUseCaches(false);
  con.setRequestProperty(
   "Content-Type",
   "application/x-java-serialized-object");

   return con;
 }

I m giving u link to a resource so that u can get all the information abt it..

http://www.frank-buss.de/echoservlet/

go there and check the example..

And also go to-->http://www.jguru.com/faq/view.jsp?EID=157

U can get all the information here

If u want to embed an Applet in a servlet then U can do like this..


Applets are client side application where as a Servlet is a Server side application.Servlet sends its response to a client in html format(default).So u can just write in the servlet this to view the applet

out.println("<applet code=\"MyApplet.class\" width=\"500\" height=\"200\"></applet>");

Now when u will run the sevlet in the output u can see the applet

Hope this can solve ur problem...

  Was this answer useful?  Yes

Soumitra Das

  • Apr 12th, 2006
 

Give me answer interview question

  Was this answer useful?  Yes

kiran

  • Apr 22nd, 2006
 

 Give me clear answer for this question.

  Was this answer useful?  Yes

sbarik

  • Apr 24th, 2006
 

U can push an Applet into a servlet by just writting the th <Applet> tag  in the servlet

eg:-

  out.println("<applet code=AccessoryFileChooser.class width=400 height=400></applet>");

  Was this answer useful?  Yes

sbarik

  • Apr 24th, 2006
 

Applet is a client side Application. wheras A servlet is a server side application.The servlet sends its resopnse as HTML (By default) to the client. U can just push the applet in servlet just by writting the <APPLET>tag in the servlet.I have written how to us it in the previous answer..

Im writin the use of <Applet> Tag in Detail--

<APPLET
        CODEBASE = codebaseURL
        ARCHIVE = archiveList
        CODE = appletFile ...or...  OBJECT = serializedApplet
        ALT = alternateText
        NAME = appletInstanceName
        WIDTH = pixels  HEIGHT = pixels
        ALIGN = alignment
        VSPACE = pixels  HSPACE = pixels
    >
    <PARAM NAME = appletAttribute1 VALUE = value>
    <PARAM NAME = appletAttribute2 VALUE = value>
    . . .
    alternateHTML
    </APPLET>

CODEBASE = codebaseURL
This OPTIONAL attribute specifies the base URL of the applet--the directory that contains the applet's code. If this attribute is not specified, then the document's URL is used.
ARCHIVE = archiveList
This OPTIONAL attribute describes one or more archives containing classes and other resources that will be "preloaded". The classes are loaded using an instance of an AppletClassLoader with the given CODEBASE.
The archives in archiveList are separated by ",". NB: in JDK1.1, multiple APPLET tags with the same CODEBASE share the same instance of a ClassLoader. This is used by some client code to implement inter-applet communication. Future JDKs may provide other mechanisms for inter-applet communication. For security reasons, the applet's class loader can read only from the same codebase from which the applet was started. This means that archives in archiveList must be in the same directory as, or in a subdirectory of, the codebase. Entries in archiveList of the form ../a/b.jar will not work unless explicitly allowed for in the security policy file (except in the case of an http codebase, where archives in archiveList must be from the same host as the codebase, but can have ".."'s in their paths.)
CODE = appletFile
This REQUIRED attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. It cannot be absolute. One of CODE or OBJECT must be present. The value appletFile can be of the form classname.class or of the form packagename.classname.class.
OBJECT = serializedApplet
This attribute gives the name of the file that contains a serialized representation of an Applet. The Applet will be deserialized. The init() method will *not* be invoked; but its start() method will. Attributes valid when the original object was serialized are *not* restored. Any attributes passed to this APPLET instance will be available to the Applet; we advocate very strong restraint in using this feature. An applet should be stopped before it is serialized. One of CODE or OBJECT must be present.
ALT = alternateText
This OPTIONAL attribute specifies any text that should be displayed if the browser understands the APPLET tag but can't run Java applets.
NAME = appletInstanceName
This OPTIONAL attribute specifies a name for the applet instance, which makes it possible for applets on the same page to find (and communicate with) each other.
WIDTH = pixels HEIGHT = pixels
These REQUIRED attributes give the initial width and height (in pixels) of the applet display area, not counting any windows or dialogs that the applet brings up.
ALIGN = alignment
This OPTIONAL attribute specifies the alignment of the applet. The possible values of this attribute are the same as those for the IMG tag: left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom.
VSPACE = pixels HSPACE = pixels
These OPTIONAL attributes specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). They're treated the same way as the IMG tag's VSPACE and HSPACE attributes.
<PARAM NAME = appletAttribute1 VALUE = value>
<PARAM NAME = appletAttribute2 VALUE = value> . . .
This tag is the only way to specify an applet-specific attribute. Applets access their attributes with the getParameter() method

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions