ВУЗ:
Составители:
Рубрика:
122
Form form = new Form("Generated form");
for (int i = 0; i < inputs.size(); i++) {
InputData input = (InputData) in-
puts.elementAt(i);
form.append(input.getComponent());
}
InputData submit = new Submit("Submit");
form.append(submit.getComponent());
display.setCurrent(form);
};
public void submit() {
String params = makeParams();
HttpConnection connection = null;
OutputStream out = null;
InputStream in = null;
try {
connection = (HttpConnection) Connector.open(
MidletFormHandler.URL + "/" + action);
connec-
tion.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty(
"Content-Type", "application/x-www-form-
urlencoded");
connection.setRequestProperty(
"Content-Length", Integ-
er.toString(params.length()));
out = connection.openDataOutputStream();
out.write(params.getBytes());
in = connection.openInputStream();
int length = (int) connection.getLength();
byte[] data = new byte[length];
in.read(data);
String response = new String(data);
Alert alert = new Alert("Response", response,
null, AlertType.INFO);
display.setCurrent(alert);
}
catch (IOException e) {
Alert alert = new Alert("I/O Error",
e.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
finally {
try {
if (out != null)
out.close();
if (connection != null)
connection.close();
Страницы
- « первая
- ‹ предыдущая
- …
- 120
- 121
- 122
- 123
- 124
- …
- следующая ›
- последняя »