i m trying to access to a servlet runnig on the tomcat server on my own pc. my MIDlet compiles bt gives exception at thr run time... i am at u can say begginers level here is my full code...... if anyone of u can spare some time...i wld b thankfull import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.util.*; import java.io.*; public class WelcomeMidlet extends MIDlet implements CommandListener { private Display display; private Form f1, f2, f3; private TextField tf1, tf2;
More>>
i m trying to access to a servlet runnig on the tomcat server on my own pc. my MIDlet compiles bt gives exception at thr run time... i am at u can say begginers level
here is my full code......
if anyone of u can spare some time...i wld b thankfull
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.util.*;
import java.io.*;
public class WelcomeMidlet extends MIDlet implements CommandListener
{
private Display display;
private Form f1, f2, f3;
private TextField tf1, tf2;
private String url, name, serv;
private Alert a1, a2;
private Command exit, submit1, submit2, back1, back2;
public WelcomeMidlet()
{
display = Display.getDisplay(this);
a1 = new Alert("", " Connection Established!", null,
AlertType.INFO);
a2 = new Alert("", " Connection Failed to Establish!", null,
AlertType.INFO);
f1 = new Form("Connect to server");
tf1 = new TextField("Enter url:", "", 25, TextField.ANY);
exit = new Command("Exit", Command.EXIT, 1);
submit1 = new Command("Submit", Command.OK, 1);
f1.append(tf1);
f1.addCommand(exit);
f1.addCommand(submit1);
f1.setCommandListener(this);
f2 = new Form("Enter name");
tf2 = new TextField("Enter name:", "", 20, TextField.ANY);
back1 = new Command("Back", Command.BACK, 1);
submit2 = new Command("Submit", Command.OK, 1);
f2.append(tf2);
f2.addCommand(back1);
f2.addCommand(submit2);
f2.setCommandListener(this);
f3 = new Form("Enter name");
f3.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(f1);
}
public void pauseApp() {
}
public void destroyApp(boolean un) {
}
public void commandAction(Command c, Displayable displayable)
{
if (c == exit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c == submit1) {
url = tf1.getString();
}
else if (c == back1) {
display.setCurrent(f1);
}
else if (c == submit2) {
name = tf2.getString();
serv = new String(url + "?" + "name=" + name);
conn(serv);
}
}
HttpConnection con1 = null;
InputStream in = null;
StringBuffer buffer = new StringBuffer();
public void conn(String serv) {
try {
con1 = (HttpConnection) Connector.open(serv);
display.setCurrent(a1);
display.setCurrent(f3);
in = con1.openInputStream();
int ch;
while ((ch = in.read()) != 1)
{
buffer.append((char) ch);
}
String line = new String(buffer.toString());
f3.append(line);
} catch (IOException e) {
a2.setTimeout(Alert.FOREVER);
display.setCurrent(a2);
}
}
}
<<Less