aspose file tools
The moose likes Servlets and the fly likes how to pass parameters from a serlet to an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to pass parameters from a serlet to an applet" Watch "how to pass parameters from a serlet to an applet" New topic

how to pass parameters from a serlet to an applet

Sim Raina
Ranch Hand

Joined: Nov 20, 2003
Posts: 33
hi everybody how u doing ?
i am making this applet and the values for the applet comes as a parameter from the servlet .I am done with my servlet and my applet the only thing that is missing now is i don know how to communicate the servlet with the applet. so any help is appreciated

if u can't impress people with ur intelligence , confuse them with ur bullshit
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12910
If all you need is to pass the applet initialization parameters, just write them into the applet tag param elements in the html page.

If you need to do it dynamically while the applet runs - this has been discussed a number of times here - search for servlet applet communcation.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Here is some code which i used for applet and Servlet comminication.
Hope this might help u.
* This method causes the applet to interact with the servlet. Basically, the
* method writes the message to the servlet, then reads the response and sticks
* it in the "response" field.
private void interactWithServlet() {
try {
// Create an object we can use to communicate with the servlet
String location = "http://pdc:7001/SP/AttributeServlet";
URL servletURL = new URL(location);
URLConnection servletConnection = servletURL.openConnection();
// Write the message to the servlet
PrintStream out = new PrintStream(servletConnection.getOutputStream());
// Now read in the response
InputStream in = servletConnection.getInputStream();
StringBuffer response = new StringBuffer();
int chr;
while ((!=-1) {
response.append((char) chr);
// responseField.setText(response.toString());
} catch (IOException e) {
// responseField.setText("An error occurred: " + e.toString());
// Read in the message from the servlet
StringBuffer msgBuf = new StringBuffer();
BufferedReader fromApplet = param_Request.getReader();
String line;
while ((line=fromApplet.readLine())!=null) {
if (msgBuf.length()>0) msgBuf.append('\n');
cat.debug("Applet servlet==================msgBuf:"+msgBuf);
// Write the message back to the applet
PrintWriter toApplet = param_Response.getWriter();
toApplet.println("I (the servlet) received a message \"" + msgBuf.toString() + "\"");
toApplet.println("at " + (new Date()).toString());
toApplet.println("and sent this text in response. Hope you enjoy it!");
I agree. Here's the link:
subject: how to pass parameters from a serlet to an applet