import java.applet.*;
import java.net.*;
import java.io.*;
import java.awt.*;
public class TestApplet extends Applet
{
private String line;
public void init () {
try {
URL url = new
URL("http://localhost:8080/webpages/Web-inf/servlets/TestServlet?
name=TestApplet");
BufferedReader in = new BufferedReader(new
InputStreamReader(url.openStream()));
line = in.readLine();
in.close();
}
catch (Exception e){e.printStackTrace();}
}
public void paint (Graphics g) {
g.drawString (line, 20, 40);
g.drawString("This is just applet drawing!", 20, 80);
}
}// testapplet
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException,
IOException
{
res.setContentType ("text/plain");
PrintWriter out = res.getWriter();
out.println ("Hello " + req.getParameter("name") + ", servlet
talking!");
out.close();
}
}// testservlet
Thanks,
Val.
Are you getting any output when you run?
The code works except that there should not be a space in
"TestServlet? name=TestApplet".
But, thats just from the servlet, if it was the applet it would
add another line afterwards.
Val.
P.S. That space is fixed in the program, just copied it wrong.