Appletee, Servletee kind of newbie question!

Discussion in 'Java' started by Andrew Tucker, Aug 23, 2003.

  1. Hi everyone,

    I am having real problems working out whats going on w/ my applet. I want to
    be able to send an object from an applet to a servlet, here is the code for
    the listener method causing the trouble:

    private void addClientListener(java.awt.event.MouseEvent evt) {

    System.out.println("Got this far, addClientListener.");
    try {
    URL fileURL = new URL(getDocumentBase(),
    "servlet/MaintSchedServ");
    URLConnection conn = fileURL.openConnection();

    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setUseCaches(false);

    conn.setRequestProperty("addClient", "true");

    ObjectOutputStream out = new ObjectOutputStream(new
    BufferedOutputStream(

    conn.getOutputStream()));

    out.writeObject(textField1.getText());
    out.close();

    } catch( Exception exc ) {
    exc.printStackTrace();
    }
    }
    I apologise if my usage of setRequestProperty is incorrect, i need to pass
    several different objects to servlet and thought that by using this method
    of URLConnection, i could evaluate this at servlet and handle each case
    seperately. If there is a better way i would love to know how!

    Here is the java console output, it is saying that i need to set doOutput =
    true, well i am aren't I?

    Thankyou in advance for any direction you can give me!!

    Andrew.

    Java(TM) Plug-in: Version 1.4.1_02
    Using JRE version 1.4.1_02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Andrew Tucker
    /*
    options
    */
    Stopping applet ...
    Unregistered modality listener
    Joining applet thread ...
    Destroying applet ...
    Disposing applet ...
    Joined applet thread ...
    Quiting applet ...
    Finding information ...
    Releasing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=0
    Caching classloader: sun.plugin.ClassLoaderInfo@4865ce
    Current classloader cache size: 1
    Done ...
    Registered modality listener
    Referencing classloader: sun.plugin.ClassLoaderInfo@4865ce, refcount=1
    Loading applet ...
    Initializing applet ...
    Starting applet ...
    Got this far, addClientListener.
    java.net.ProtocolException: cannot write to a URLConnection if
    doOutput=false - call setDoOutput(true)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown
    Source)
    at AWTMaintSchedGUI.addClientListener(AWTMaintSchedGUI.java:114)
    at AWTMaintSchedGUI.access$000(AWTMaintSchedGUI.java:17)
    at AWTMaintSchedGUI$1.mouseClicked(AWTMaintSchedGUI.java:51)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Button.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
     
    Andrew Tucker, Aug 23, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elmo Watson

    Different kind of Checkbox question

    Elmo Watson, Apr 13, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    Elmo Watson
    Apr 13, 2005
  2. ali
    Replies:
    2
    Views:
    390
    Ross Bamford
    May 11, 2005
  3. Replies:
    3
    Views:
    372
  4. Joseph Turian
    Replies:
    11
    Views:
    522
    Joseph Turian
    Jan 19, 2005
  5. Jerry C.
    Replies:
    8
    Views:
    250
    Uri Guttman
    Nov 23, 2003
Loading...

Share This Page