Note that there are some explanatory texts on larger screens.

plurals
  1. POSend data to jsp from android
    text
    copied!<p>i´m trying to send data to a jsp file running on localhost.. When i click submit on my phone, the application fails, and shows me <em>Unfortunately, application has stopped.</em></p> <p><strong>LoginTask:</strong></p> <pre><code>public class LoginTask extends AsyncTask&lt;String, Void, Integer&gt; { private ProgressDialog progressDialog; private LoginActivity activity; private int id = -1; public LoginTask(LoginActivity activity, ProgressDialog progressDialog) { this.activity = activity; this.progressDialog = progressDialog; } @Override protected void onPreExecute() { progressDialog.show(); } @Override protected Integer doInBackground(String... arg0) { String result = ""; int responseCode = 0; try { HttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://192.168.1.100:8080/test/AndroidCheck.jsp"); List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("username", arg0[0])); nameValuePairs.add(new BasicNameValuePair("password", arg0[1])); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); int executeCount = 0; HttpResponse response; do { progressDialog.setMessage("Logging in.. ("+(executeCount+1)+"/5)"); executeCount++; response = client.execute(httppost); responseCode = response.getStatusLine().getStatusCode(); } while (executeCount &lt; 5 &amp;&amp; responseCode == 408); BufferedReader rd = new BufferedReader(new InputStreamReader( response.getEntity().getContent())); String line; while ((line = rd.readLine()) != null) { result = line.trim(); } id = Integer.parseInt(result); } catch (Exception e) { responseCode = 408; e.printStackTrace(); } return responseCode; } @Override protected void onPostExecute(Integer headerCode) { progressDialog.dismiss(); if(headerCode == 202) activity.login(id); else activity.showLoginError(""); } } </code></pre> <p><strong>LoginActivity:</strong></p> <pre><code>public class LoginActivity extends Activity { protected static final int LOGIN_REQUEST_CODE = 0; protected static final int RECOVER_REQUEST_CODE = 1; protected static final int REGISTER_REQUEST_CODE = 2; public static final int LOGOUT_RESULT_CODE = 2; SharedPreferences sharedPreferences; private EditText username; private EditText password; private Button btnLogin;; private final Class&lt;?&gt; LOGIN_DESTINATION = AndroidNavigationTabsActivity.class; @Override protected void onCreate(Bundle savedInstanceState) { sharedPreferences = getPreferences(MODE_PRIVATE); super.onCreate(savedInstanceState); if( sharedPreferences.getBoolean("user_logged_in", false)) { startActivityForResult( new Intent(LoginActivity.this, LOGIN_DESTINATION), LOGIN_REQUEST_CODE); } setContentView(R.layout.login_activity); username=(EditText)this.findViewById(R.id.username); password=(EditText)this.findViewById(R.id.password); btnLogin=(Button)this.findViewById(R.id.btnLogin); btnLogin.setOnClickListener(loginOnClickListener); } protected OnClickListener loginOnClickListener = new OnClickListener() { public void onClick(View v) { ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this); progressDialog.setMessage("Logging in..."); progressDialog.setCancelable(false); LoginTask loginTask = new LoginTask(LoginActivity.this, progressDialog); loginTask.execute(username.getText().toString(),password.getText().toString()); } }; public void showLoginError(String result) { AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.setMessage(R.string.login_invalid_error); AlertDialog alert = builder.create(); alert.setCancelable(false); alert.show(); } public void login(int id) { sharedPreferences.edit().putBoolean("user_logged_in", true).commit(); startActivityForResult( new Intent(LoginActivity.this, LOGIN_DESTINATION), LOGIN_REQUEST_CODE); } } </code></pre> <p>When i hit <strong>Submit</strong> on my phone, it shows me Error(Toast). The jsp page(AndroidCheck.jsp) shows me <code>null</code> (i´m trying to show on webpage, what i type in my phone:username and login). I have no idea, where is the problem...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload