I'm trying to set up an
Applet to send an ArrayList of objects to a
servlet.
Though the code works fine in local debug mode (locally), when I execute the code below from the applet to the Servlet, nothing happens in the servlet.
I click the button which "should" post the data from the Applet, but no XML file is created. I've put various messageboxes in the servlet code below, but ***none of them fires***.
Perhaps this is a
Tomcat setup issue, but I'm not sure...I get no error screens. I just remain on the applet after clicking the "post" button with no files created.
Thanks for anybody's advice or ideas.
-- Mike
Applet code that sets up a call to the servlet:
.
.
.
ObjectOutputStream outputToServlet;
try
{
// finally, create the URL.
URL dataURL = new URL(
"http://localhost:8081/servlet/tp.HomeServlet");
URLConnection servletConnection = dataURL.openConnection();
// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
// Specify the content type that we will send binary data
servletConnection.setRequestProperty(
"Content-Type", "application/x-java-serialized-object");
// send the Pilates ArrayList object to the servlet using serialization
outputToServlet = new ObjectOutputStream(
servletConnection.getOutputStream());
// serialize the object
// finalClassSchedule is an ArrayList of objects.
outputToServlet.writeObject(finalClassSchedule);
outputToServlet.flush();
outputToServlet.close();
}
catch (Exception mfe)
{
mfe.printStackTrace();
}
Servlet code that receives this call:
public class HomeServlet extends HttpServlet implements Serializable
{
static final private
String CONTENT_TYPE ="application/x-java-serialized-object";
ObjectInputStream inputFromApplet = null;
ArrayList classSchedule = null;
//Initialize global variables
public void init() throws ServletException
{
JOptionPane.showMessageDialog(null, "inside servlet init."); //never is seen
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
response.setContentType(CONTENT_TYPE);
// get an input stream from the applet
inputFromApplet = new ObjectInputStream(request.getInputStream());
JOptionPane.showMessageDialog(null, "inside get in servlet"); // never is seen
ObjectInputStream appletIn =
new ObjectInputStream(request.getInputStream());
classSchedule = (ArrayList) appletIn.readObject();
appletIn.close(); // close stream.
// write data to createXML
CreateXML xml = new CreateXML("finalXMLFile.xml",
classSchedule,
"schedule.xsl");
}
catch (Exception e)
{JOptionPane.showMessageDialog(null, "Error in servlet Get");}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request, response);
}
//Clean up resources
public void destroy()
{
}
}