• Post Reply Bookmark Topic Watch Topic
  • New Topic

http connection to servlet...  RSS feed

Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hiya all,
im constructing a midlet which interacts with a servlet... return the result and display the result in a new screen. here's my earlier code...
public void commandAction(Command c, Displayable d)
if (d==_connection)//while in conn screen
if (c==getConnectCommand())//return key press
msg = createSession();//run the conn function and return string..
displayReportScreen(msg); //this function calls a new form class and display returned message....
}//end connect call
}//end commandAction
public String createSession()
String userID = "Shin";
String password = "TylerDurden";
HttpConnection hc = null;
InputStream in = null;
String url = "http://localhost:8080/midp/hits?userID="+userID+"&password="+password;
try {
hc = (HttpConnection)Connector.open(url);
in = hc.openInputStream();
int contentLength = (int)hc.getLength();
byte[] raw = new byte[contentLength];
int length = in.read(raw);
// Show the response to the user.
String s = new String(raw, 0, length);
catch (IOException ioe) {
return s;
private void displaySessionsucScreen(String msg)
_sessionsuc = new Sessionsuc(msg);//form class
_display.setCurrent( _sessionsuc);

now, when i tried running this, the process automatically locks up at the midp default 'send out going data warning' screen... my display method is never ran.
im not sure what cause this... but later i tried threading the conn event, it's able to retrieve signal back from servlet... later, i tried threading the connection process with this code..
here my threading code...
Thread t = new Thread()
public void run()
msg = createSession();
the servlet is contacted and returned a message. but problem is that thread called is done after the main thing (disply) has done running... which should surpose to be other way round with the thread finishing up returning the msg for display...
can someone please tell me how do i effectively control thread, which i have a bundle of them at hand and how do i have them executed orderly to return result?
many thanks in advance...
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ryan,
open the preference --> security
and set the security domain to "trusted"
Hope this may help
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!