• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

http connection to servlet...

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
in.close();
hc.close();
// Show the response to the user.
String s = new String(raw, 0, length);
}
catch (IOException ioe) {
System.out.println(ioe);
}
return s;
}
private void displaySessionsucScreen(String msg)
{
_sessionsuc = new Sessionsuc(msg);//form class
_sessionsuc.setCommandListener(this);
_display.setCurrent( _sessionsuc);
System.gc();
}

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();
}
};
t.start();
displayReportScreen(msg);
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...
cheers,
ryan.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ryan,
open the preference --> security
and set the security domain to "trusted"
Hope this may help
Naveen
reply
    Bookmark Topic Watch Topic
  • New Topic