R
Robert
Hi group,
when I run the following example code, everything works fine as for
the applet gets a response from the serber and displays it. What it
displays is not what it is supposed to display though. It should
display "Hello TestApplet servlet talking!". What I get is a cryptic
string that looks like binary code.
I would appreciate any hints on what I could do to get the real output
string.
Rob.
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://127.0.0.1/servlets/test?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);
}
}
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();
}
}
when I run the following example code, everything works fine as for
the applet gets a response from the serber and displays it. What it
displays is not what it is supposed to display though. It should
display "Hello TestApplet servlet talking!". What I get is a cryptic
string that looks like binary code.
I would appreciate any hints on what I could do to get the real output
string.
Rob.
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://127.0.0.1/servlets/test?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);
}
}
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();
}
}