Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Servlet-Interview-Questions servlet to applet communication

Have Programming Question? Ask it here!
 
 
 


pravat kumar dash
servlet to applet communication
1 Answer(s)      a year and 9 months ago
Posted in : Servlet Interview Questions


good morning sir. how to read one text field from servlet and display that value in applet? thanks


Advertisement
View Answers

August 1, 2012 at 10:44 AM


We are providing you the code that will display the message sent from the servlet to applet.

1)Here is the code of 'ServletExample.java'

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletExample extends HttpServlet{
public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException , IOException{

ObjectOutputStream output = null;
try{
output = new ObjectOutputStream(response.getOutputStream());
String str = new String("Hello World");
output.writeObject(str);
output.flush();
output.close();
System.out.println("Message is===== " + str);
}
catch( Exception e){
e. printStackTrace();
}
}
}

2)Now call the servlet with the 'AppletCallingServlet.java'

import java.io.*;
import java.awt.*;
import java.net.*;
import java.applet.*;

public class AppletCallingServlet extends Applet{
URL url = null;
URLConnection servletConnection = null;
public void init()
{
try{
url = new URL("http://localhost:8080/examples/ServletExample";;);
servletConnection = url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
}
catch(Exception e){
e.printStackTrace();
}
}
public void paint(Graphics g)
{
try{
ObjectInputStream input = new ObjectInputStream(servletConnection.getInputStream());
g.drawString("Applet Servlet Communication",50,50);
String str = new String();
str = (String)input.readObject();
g.drawString(" Message sent from server: " + str,50,100);

input.close();
}
catch( Exception e)
{
e.printStackTrace();
}
}
}

3)Call this applet with the html file.

<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=AppletCallingServlet.class width=500 height=500>
</applet>
</body>
</html>


Related Tutorials/Questions & Answers:
applet servlet communication - Applet
()); g.drawString("Applet Servlet Communication",50,50); String str = new String(); str...applet servlet communication  Can anybody tell me applet - servlet communication by creating a webproject in eclipse. I am creating a web
servlet to applet communication
(servletConnection.getInputStream()); g.drawString("Applet Servlet Communication",50,50); String str...servlet to applet communication  good morning sir. how to read one text field from servlet and display that value in applet? thanks   We
Advertisements
jsp applet communication - JSP-Servlet
jsp applet communication  Hi... We've an application where v need to create an object in the jsp and send that to an applet... For this v used... not sending as an object... so..How to get that object in the applet
Applet JSP communication - Applet
Applet JSP communication  Hi.. I've an application where i need to get the data from the applet to JSP... How can i do this..?? can anyone explain with a sample code
Servlet and Applet - Applet
Invoke and run an Applet from Servlet  How can i invoke and run an applet from servlet. Can anyone provide me the sample code
servlet code - Applet
servlet code  how to communicate between applet and servlet ... from the servlet to applet. Here is the code of 'ServletExample.java... ObjectInputStream(servletConnection.getInputStream()); g.drawString("Applet Servlet
Loading JApplet into Servlet - Applet
Loading JApplet into Servlet  Hi, I am in need of loading javax.swing.JApplet in a Serlvet. This should work for all the browsers. Firefox 2.0, Mozilla 1.7... Could you let me know the procedure to load applet into servlet
diff b/w applet and servlet
diff b/w applet and servlet  what is the difference between applet and servlet?   Difference between servlet and applet: 1)An applet is client side programming whereas servlet is server side programming. 2)Applets run
JSP Applet Tag - JSP-Servlet
JSP Applet Tag  Hi, I am using Eclipse Ganymede. I have develloped... and my applet(Basic Hello World Applet) under Java Resources folder. I have jsp plugin type as applet in my jsp. When I run this jsp on Server(Tomcat6.0
Applet
Applet  Write an applet to display a string in an applet. String should be passed as a parameter to an applet
applet
applet  What is the immediate superclass of the Applet class
Applet
Applet  how to run an applet on a web browser
applet
applet  Explain different stages in the lifecycle of an applet with figure.   Stages of Applet: Life cycle of an Applet: init(): This method is called to initialized an applet start(): This method is called after
Applet
Applet  Give the class hierarchy of an Applet class
Applet
Applet  Write a ava applet that sets blue color foreground and yellow color background at the start of an applet
Applet
Applet  Explain the start() and stop() methods of applet life cycle.   Start and Start method of Applet Life Cycle Start () method: The start method of an applet is called after the initialization method init
Applet
Applet  Write a short note on applet life cycle
Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet
Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials
Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red
applet
applet  applet to open new tab not working.here's my code import java.applet.*; import java.awt.*; import java.net.*; import java.awt.event.*; public class NewURL extends Applet implements ActionListener{ public void init
Communication Tube
Communication Tube       Communication Tube - web messenger chat client for the popular IM (instant messaging) networks: ICQ , MSN Messenger, Google Talk (GTalk) , IRC Read full
Communication Portal
Communication Portal       A communication interface desinged with Web 2.0 technology, mission is to help peolpe communicate easily over a comfortable web interface Read full Description
applet - Applet
.  Hi Friend, Try the following code: 1)Create an applet... extends Applet{ public void paint(Graphics g){ g.drawString("Welcome in Java Applet.",40,20); } } 2) Call this applet with html code
Applet - Applet
Applet  what is the concept of applet? what is different between the applet concept and HTML? what is mean by swing?  Hi friend, Applet Applet is java program that can be embedded into HTML pages. Java applets
project in java using applet and servlet...which tool i should use?eclipse or netbeans?
project in java using applet and servlet...which tool i should use?eclipse or netbeans?  i want to do a project in java using applet and servlet...which tool i should use?eclipse or netbeans
applet - Applet
*; import java.awt.*; public class CreateTextBox extends Applet implements.../applet/ Thanks
Interthread Communication
Inter-Thread Communication   ... communication among threads which reduces the CPU?s idle time i.e. A process where...; This technique is known as Interthread communication which is implemented by some
Applet - Applet
Applet   Namaste, I want to create a Menu, the menu name is "Display... java.awt.event.*; public class menu2frame extends Applet implements WindowListener...------------------------"); g.drawString("Demo of Java Applet Window Event Program"); g.drawString("Java
Communication Effectiveness in Outsourcing, Communication Techiques in Outsourcing
Communication Effectiveness in Outsourcing  Introduction A good part of the communication in outsourcing relationships is achieved... to communicate, the success of communication increases in the order of email, telephone
applet and servelet
applet and servelet  How will you establish the connection between the servelet and an applet?  Hi, From applet you can use the URL class to call the servlet. URL servletURL = new URL( location ); URLConnection
java - Applet
java  how to communicate to my servlet through applet.   ... this information to the servlet in the normal way. The applet pretends to be a web browser, and the servlet doesn't know the difference. The servlet
digital communication system
digital communication system  A digital communication system capable of interconnecting, a large number of computers, terminals and other peripheral devices within a limited geographical area is called- a) LAN, B) WAN, C
Data over Voice Communication
Data over Voice Communication  I just Want to know that Data Over Voice communication is possible in India or Not, If not then Why. and If Yes then Why Please anyone give the answer
Inter Thread Communication
Inter Thread Communication  what is inter thread communication?   hi friend, Inter thread communication is a process of communication between two threads. In this process, a thread outside the critical section is tried
applet problem - Applet
applet problem  How can I create a file in client side by a java applet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
Interthread Communication in Java
Interthread Communication in Java As you know about producer-consumer problem... wasting of cycle or polling, interthread communication is a good way.  Given below some function helpful in interthread communication : Methods
Inter Server Communication - Struts
Inter Server Communication   Hi In my project I am using Struts2.0 ,I have 2 server one is web-logic server and another is Tomcat server. In web-logic server , there is link to call tomcat server for call struts application
embedding class in an applet - Applet
embedding class in an applet  I have an applet that has a set... java.awt.event.*; public class tesURL extends Applet implements ActionListener... a remote controller). I have the applet code for the remote controller
Applet codebase
Applet codebase  What is codebase in applet
creating hyperlinks in applet - Applet
creating hyperlinks in applet  Dear sir, how can i move from one applet to another applet and how can i use previous applet input data in anotherapplet(just like session tracking) thanks
java - Applet
java  what is applet
applet program code - Applet
applet program code  hello sir, i did't get the code for below problem... please help me... 1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y
applet running but no display - Applet
applet running but no display  Hai, Thanks for the post. I have... from a client, the page appears with a blank applet part (just whitescreen..., it is showing that the "Applet as1 started". Please help me to solve this issue
What is Applet? - Applet
What is Applet?  What is Applet?  Hi,Here is a little information about Applet.An applet is a little application. Prior to the World Wide... programming language, an applet is a small program that can be sent along with a Web
loading Java Applet - Applet
loading Java Applet  Hi, I use the archive tag to download my applet into the Browser It takes too long to load. Can I do it in several steps... control the loading within the applet? thanks
java applet - Applet
java applet  wants to creat address bar on my java applet.  Hi Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
 

 

 

DMCA.com