Java Reference
In-Depth Information
L ISTING 6.8
Continued
// It could be CORBA/RMI client
// It could be a database query, etc.
order.setStatus(“Your order is in transit.”);
}
//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.
Order order = (Order)ois.readObject();
getOrderStatus(order);
// The Response Begins Here
response.setContentType(“application/octet-stream”);
ObjectOutputStream oos =
new ObjectOutputStream(response.getOutputStream());
// Echo the object to the response
oos.writeObject(order);
oos.flush();
oos.close();
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe.getMessage());
}
}
//Get Servlet information
public String getServletInfo() {
return “OrderStatusServlet Information”;
}
}
Search WWH ::




Custom Search