This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing an app for connecting to a servlet.

 
Julio C Moreno
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

i�m trying to connect to a servlet using a midlet using the next code :

try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since","11 May 2005 15:17:19 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Languaje","en-CA");
c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

os = c.openOutputStream();

os.write( ("nombre="+myname).getBytes() );
os.flush();

is=c.openDataInputStream();
int ch;
while( (ch = is.read()) != -1){
b.append( (char) ch );
System.out.print( (char) ch );
}
t= new TextBox("fecha", b.toString(),1024,0 );
t.setCommandListener(this);
} finally {
if(is !=null){
is.close();
}
if( os != null){
os.close();
}
if ( c !=null){
c.close();
}

now im using the netbeans 4.0 ide for test my code and this is
the message displayed : It is ok to use airtime ?

Apreciatelly Mark could u give me some tip for finalize my homework ?

regards
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will always get this question if you do not have the SecurityPermission granted for using HttpConnection. Basically you are calling out to the internet, for most people this costs them money on their phone, so you can't just have an application connect and cost them money without getting their "approval".

That is what that message is, just select "yes" or "ok" to allow the connection.

When you get that message, there are a few options.

1. Just this once
2. For just this running of the application.
3. Always for this application, now and in the future.

Note that using the wireless toolkit, I believe it doesn't keep you last choice, so each time you run your app through the toolkit, you should be asked this question.

Mark
 
Julio C Moreno
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for ur comments mark , it is true that the user need to give permission for connect to the internet.

Now in my app, i answered with yes and nothing happens , so i've the same problem , and yes my code in the server is jsp .

any help would be appreciated.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't think you can call a JSP page from J2ME.


I could be wrong, but with the JSP being converted into a Servlet by the web container at the time it is first called up, means that you won't know the name of the generated Servlet, so you can't call it because you don't know the name and address of that Servlet.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic