Java Reference
In-Depth Information
L ISTING 6.4
StudentListTunnelServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import StudentList;
public class StudentListTunnelServlet extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
super.init(config);
}
//Service the request
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
// Create the ObjectInputStream with
// the Request InputStream.
ObjectInputStream ois =
new ObjectInputStream(request.getInputStream());
// Read the Object. Make sure the StudentList Object
// is in your CLASSPATH or you will receive a
// ClassNotFoundException.
StudentList list = (StudentList)ois.readObject();
// The Response Begins Here
response.setContentType(“application/octet-stream”);
ObjectOutputStream oos =
new ObjectOutputStream(response.getOutputStream());
// Echo the object to the response
oos.writeObject(list);
oos.flush();
oos.close();
}
catch (ClassNotFoundException cnfe) {
Search WWH ::




Custom Search