Authenticating a user (in the web application typically Servlet) with his credentials from Android application
I am trying to develop an Android application which typically allows users to login (authentication has to be done in the web application. I already have a Servlet which takes username and password and returns success or failure as result in XML format) with their credentials and do some operations (like view, update delete) on the 开发者_Python百科data specific to that user.
I found that we have to use REST way of doing this. I am not sure if I understood it correctly. Can someone direct me the way I should proceed to develop this kind of Android application?
Thanks, Prasanth
The easiest way I did this was using GET. Just load the credentials to your URL and load that url
username = et1.getText().toString(); password = et2.getText().toString();
String url = "http://www.abc.com?action=ru?loginid="+username+"paswd="+password; wv.loadUrl(url);
If you just do the above, you can see "successful" on your screen. If you want to catch this and put a validation, do the following:
InputStream isText = text.openStream();
byte[] bytes=new byte[isText.available()];
isText.read(bytes);
String s = new String(bytes);
System.out.println(s);
if(s.equals("unavailable"))
{
String s1="OK";
AlertDialog.Builder ad=new AlertDialog.Builder(Registration.this);
ad.setMessage("username already exists");
ad.setPositiveButton(s1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
ad.show();
return;
}
精彩评论