Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Sockets and Internet Protocols and the fly likes String sending in an applet to servlet servlet to applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "String sending in an applet to servlet servlet to applet" Watch "String sending in an applet to servlet servlet to applet" New topic
Author

String sending in an applet to servlet servlet to applet

The_Hobo_Phoenix
Greenhorn

Joined: Jan 22, 2003
Posts: 3
I have a problem in sending strings and i dont know where to put the code to transfer the string can anyone help please
Where do i put this code to send a string from the applet to the servlet and from the servlet to the applet.
// this is my applet
import java.applet.Applet;
import java.awt.*; // import the java.awt package
import java.awt.event.*; // import the java.awt.event package
import java.lang.*;
import java.lang.String;
import java.sql.*;//?
import java.io.*;
import java.util.*;//?
import java.net.*;
import javax.swing.*;//?

public class tta1 extends Applet implements ActionListener {
public void init()
{
}//init

public void paint(Graphics g)
{
//outputting strings too screen here, into cells in a timetable.
}//paint()

// process user's action in TextField input
public void actionPerformed( ActionEvent e )
{

repaint();//Force paint to be invoked
}
}//tta1
//this is the servlet-------------------------------------------------

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class SerChk extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables

public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<font color=\"green\">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</font>");
String outputline;
while((outputLine = out.writeline()) != null)
system.out,println(inputLine);
in.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>SerChk</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}

//buffer code----------------------------------------

import java.net.*;
import java.io.*;
public class URLConnectionReader{
public static void main(string[] args) throws Exception {
URL myUrl = new URL("http://");
URLConnection uc = myURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream())));
String inputline;
while((inputLine = in.readline()) != null)
system.out,println(inputLine);
in.close();
}}
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Please review our naming policy and change your display name. Thanks.
You cannot actively send anything from a servlet to an applet, really, although you can often achieve the same thing by polling (i.e. the applet submits a request to the servlet to see if there's any update waiting).
- Peter
 
 
subject: String sending in an applet to servlet servlet to applet