tags:

views:

209

answers:

2

I am using this code to connect Servlet. Mobile application when try to access internet.

The following Message will appears in mobile.

"Allow network access?? yes or no ". If i click "no" for that message in Nokia 6300 "Application Error" Warning will appear and it will close the application automatically.

I tried other nokia mobiles like N70 and N72. Mobile will not show "Application Error".

Can any one helps me. is it Mobile problem or coding problem,

Is there any Efficient way to connect Servlet using http

public static InputStream getDataInputStream(String url, String request) {

    HttpConnection httpConnectionObj = null;

    OutputStream dataOutputStreamObj = null;

    try {
        httpConnectionObj = (HttpConnection) Connector.open(url, Connector.READ_WRITE);

        httpConnectionObj.setRequestMethod(HttpConnection.POST);

        dataOutputStreamObj = httpConnectionObj.openOutputStream();

        dataOutputStreamObj.write(request.getBytes());

        dataOutputStreamObj.close();

        return httpConnectionObj.openInputStream();

    } catch (javax.microedition.io.ConnectionNotFoundException cnfe) {
      //Alert
    } catch (Exception ex) {
      //Alert
    } finally {
        try {
            if (httpConnectionObj != null) {
                httpConnectionObj.close();
                httpConnectionObj = null;
            }

        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
    return null;
}
A: 

I don't sure if it would help, but try closing output stream before HttpConnection in finally block:

... } finally { try { if (dataOutputStreamObj != null) dataOutputStreamObj.close(); dataOutputStreamObj = null; if (httpConnectionObj != null) httpConnectionObj.close(); httpConnectionObj = null; } catch (IOException ex) { ex.printStackTrace(); } }
Pavel Alexeev
A: 

There is no good way to extract java.lang.Throwable.printStackTrace() on a Nokia 6300 since it is a Series40 phone.

The issue with the permission dialog has nothing to do with your code. You have to be aware of the MIDP security model in order to fix this.

A given phone has several security domain encoded in its firmware by the phone manufacturer.

In each domain, there can be several options to restrict access to a sensitive API.

When you install a MIDlet, the phone decides which domain it belongs to based on who trusts the certificate you signed it with. (could be unsigned, trusted third party, operator, manufacturer... )

When you run the MIDlet, every time it attempts to use a restricted API, the corresponding option is applied. (Could be always deny, ask the user every time, ask the user only once, always allow).

Different restricted APIs can have different options in the same domain.

There are therefore several possible explanations to your problem:

  • You signed the MIDlet differently for 6300 and N70.
  • The security domains are different on 6300 and n70.
  • The option to restrict HTTP connection is different on 6300 and N70.
  • The Mobile Network Operator is different on 6300 and N70.
QuickRecipesOnSymbianOS