import import import import

java.applet.Applet; java.net.*; java.io.*; java.awt.*;

public class Writeit extends Applet { Panel center; GridBagLayout gbl; GridBagConstraints gbs; TextArea info; Button send; public void init() { setLayout(new BorderLayout()); setBackground(Color.white); gbl = new GridBagLayout(); center = new Panel(); center.setLayout(gbl); gbs = new GridBagConstraints(); gbs.fill = GridBagConstraints.NONE; gbs.gridwidth = GridBagConstraints.REMAINDER; gbs.weightx = 1.0; showApp(); validate(); }

All we're doing in the code above is to set the form display. This could be done in a myriad of ways, and is merely a matter of preference. Now we'll handle the click event that will send the data to the URL:
public boolean action(Event e, Object o) { if (e.target.equals(send)) { try { writeMessage(); } catch (Exception e1) { } } return true; } public void writeMessage() throws Exception { String data; data = info.getText(); SendData(data); }

The data is retrieved and sent to the CGI file. On the client side, the data is written into the form element named "info". The getText function gets the data from the form element info. The data is then sent to the CGI via the SendData function.
public void showApp() { gbs.anchor = GridBagConstraints.WEST; center.add(info = addTextArea(3,50)); gbs.anchor = GridBagConstraints.CENTER;

} } .readLine()) != null) { } in.yourdomain. con.print(data). con. data."www.length()+""). we are defining the Content-type to be text/plain.setDoOutput(true). int cols) { TextArea ta = new TextArea(rows. } public void SendData(String data) throws Exception { URL url = new URL("http". "text/plain"). con.com". out. URLConnection con = url.setRequestProperty("Content-type".yourdomain. As this is using a CGI POST to send the data (as opposed to a GET in which the data would be appended to the end of the URL i.close().flush().getOutputStream()). cols). http://www.e. we have opened the URL using openConnection(). String s. ta. gbs).getInputStream()). } public TextArea addTextArea(int rows. out.close(). return ta.center. con. DataInputStream in = new DataInputStream(con. while ((s = in.setConstraints(ta. add("Center". PrintStream out = new PrintStream(con.setRequestProperty("Content-length".add(send = new Button("Write it!")). out.setUseCaches(false).com/cgi-bin/writeit?myinfo).setDoInput(true).setBackground(Color. "/cgi-bin/wdwrite").openConnection(). Once again. gbl. con.white). center).

Sign up to vote on this title
UsefulNot useful