Posted By:
Guanglin_du
Posted On:
Thursday, March 21, 2002 10:44 PM
Dear Abdul,
In your case, Im afraid, you have to learn how Applet-Servlet communicate and Java3D programming as well.
You can refer to
Dennis J Bouviers excellent tutorial (PDF format) Getting Started with the Java 3D(TM) APIat
http://java.sun.com/products/javamedia/3d/collateral for Java3D programming.
As of Applet-Servlet communication programming, the following code lines Im using in my project are for Servlet and Applet, respectively
The complete Servlet code:
import java.io.*;
import java.net.*;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TraceServlet extends HttpServlet {
// Handle the HTTP POST method.
public void doPost (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out;
String title = "TraceServlet Output";
String userQuery = request.getQueryString();
//Get the user's IP & the PC's name
String userIP = request.getRemoteAddr();
InetAddress inet = InetAddress.getByName(userIP);
String userID = inet.getHostName();
// System.out.println();
System.out.println("The POSTed tracer: "+userQuery+".");
// System.out.println("userIP = " + userIP);
// System.out.println("userID = " + userID);
ServletInputStream in = request.getInputStream();
int i = in.read();
while (i != -1) {
System.out.print((char) i);
i = in.read();
}
}
}
The Applet code fragment to write to Servlet and read from Servlet response:
try {
URL testServlet = new URL(location + "MeshServlet?myMesh");
URLConnection servletConnection = testServlet.openConnection();
//Inform the connection that we will send output and accept input
servletConnection.setDoOutput(true);
servletConnection.setDoInput(true);
// Don't use a cached version of URL connection.
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
//POST the request data (html form encoded)
PrintStream out = new PrintStream(servletConnection.getOutputStream());
out.println(URLEncoder.encode("mesh")+"="+URLEncoder.encode("WireFrame"));
out.close();
//Read the POST response data
InputStream in = servletConnection.getInputStream();
// InputStreamReader inReader = new InputStreamReader(in);
int i = in.read();
while (i != -1) {
i = in.read();
}
in.close();
} catch (Throwable t) {
t.printStackTrace();
}
Hope they are of help for you. Regards.