Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Applet to Servlet communication

843841Apr 14 2003 — edited Apr 18 2003
Hi,
Below is the code for a very simple servlet. When I type in the browser:"http://localhost:8080/servlet/myApp/TestingServlet", I get the html greeting page back.
Further below you will find the code for a simple applet that tries to invoque the same servlet. At the bottom you will find even the .html file that invoques the applet. debWindow is a window where I display diagnostic messages. When I run the html file with appletviewer, I can see in debWindow the line that invoques the servlet, but I can't see any response from the servlet.
I hope you can point to me what I'm doing wrong.
Thanks,
Miguel


// this is the servlet code
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestingServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Servlet Testing</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Welcome to the Servlet Testing Center");
out.println("</BODY>");
out.println("</HTML>");
}
}

// here is the applet
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class TestApp extends JApplet {
public void init() {
ConsoleWindow debWindow = new ConsoleWindow();
debWindow.init();
String inline = "http://localhost:8080/servlet/myApp/TestingServlet";
debWindow.prnt("Request: " + inline);
try {
URL url = new URL(inline);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String outline;
while((outline = in.readLine()) != null) {
debWindow.prnt("outline: " + outline);
}
} catch (IOException ex) {
}
}
}

// this is the .html file
<HTML> <HEAD>
<TITLE>Test/TITLE></HEAD>
<BODY>
<APPLET CODE="TestApp.class"
WIDTH = 500 HEIGHT = 400 MYSCRIPT>
</APPLET></BODY></HTML>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2003
Added on Apr 14 2003
3 comments
281 views