2

我开发了登录表单android应用程序。在这里,我必须实现忘记密码字段。如果我点击那个忘记密码,textview那么它将进入下一个活动。

下一个活动将接收用户的电子邮件,并从调用 soap 的 mysql 数据库检查其验证webservices

我已经完成了上述部分。

现在我必须实现以下部分:

电子邮件有效意味着从 mysql 数据库中获取密码并将这些密码发送到有效的电子邮件。

如何在我的 java webservice 代码中实现这部分。请帮助我。给我一些解决方案。

这是我用于检查电子邮件有效或无效的 java webservice 代码:

public class Checkemail {
public String authentication(String Email){

String retrievedUserName = "";

String status = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
 PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers WHERE email = '"+Email+"'");
 ResultSet result = statement.executeQuery();

 while(result.next()){
 retrievedUserName = result.getString("email");

 }

 if(retrievedUserName.equals(Email)){
 status = "Valid Email";
 }

 else{
  status = "Invalid Email!!!";
      }

      }
        catch(Exception e){
         e.printStackTrace();
         }
       return status;

          }

             }

这是我的安卓代码:

        public class Login extends Activity {
       private final String NAMESPACE = "http://xcart.com";
       private final String URL = "http://10.0.0.75:8080/XcartLogin/services/Checkemail?wsdl";
       private final String SOAP_ACTION = "http://xcart.com/authentication";
       private final String METHOD_NAME = "authentication";
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.login);
       Button login = (Button) findViewById(R.id.btn_login);
       login.setOnClickListener(new View.OnClickListener() {

       public void onClick(View arg0) {
         loginAction();
         }
         });
         }

      private void loginAction(){
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

             EditText Email = (EditText) findViewById(R.id.tf_userName);
            String email = Email.getText().toString();


             //Pass value for userName variable of the web service
          PropertyInfo unameProp =new PropertyInfo();
           unameProp.setName("Email");//Define the variable name in the web service method
         unameProp.setValue(email);//set value for userName variable
         unameProp.setType(String.class);//Define the type of the variable
         request.addProperty(unameProp);//Pass properties to the variable
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
          try{
          androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
           String status = response.toString();
           TextView result = (TextView) findViewById(R.id.tv_status);
           result.setText(response.toString());
             }
            catch(Exception e){

          }
          }
          }

如何在 java webservice 代码中实现获取密码发送到电子邮件?

4

2 回答 2

1

由此代码使用,它对您有帮助...

  String email_id = etxt_user.getText().toString();
  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  request.addProperty("Email", email_id);
   Pattern EMAIL_ADDRESS_PATTERN =Pattern.compile(
         "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
         "\\@" +
         "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
         "(" +
         "\\." +
         "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
         ")+");
    Matcher matcher = EMAIL_ADDRESS_PATTERN.matcher(email_id);
    if(matcher.matches()){
     Log.v(TAG, "Your email id is valid ="+email_id);
   //  System.out.println("Your email id is valid ="+email);
    }
    else{
  //  System.out.println("enter valid email id");
  Log.v(TAG, "enter valid email id" );
   }
  SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  soapEnvelope.dotNet = true;
  soapEnvelope.setOutputSoapObject(request);
  HttpTransportSE aht = new HttpTransportSE(URL);
  try {
    aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
    aht.call(SOAP_ACTION, soapEnvelope);
    SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
    Log.v("TAG", String.valueOf(resultsRequestSOAP));
   } catch (Exception e) {

     e.printStackTrace();
  }

}
于 2012-12-13T06:12:45.633 回答
0

使用这个代码..它对你很有帮助.....

 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.net.Authenticator;
 import java.net.PasswordAuthentication;
 import java.net.URL;
 import java.net.URLConnection;
 import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;

  public class Connect extends Activity {
static StringBuilder sb;

   @Override
public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     String strURL = "http://hostserver/";
    final String username = "username";
    final String password = "password";
    Authenticator.setDefault(new Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication pa = new PasswordAuthentication  
                                     (username, password.toCharArray());
                System.out.println(pa.getUserName() + ":" + new 
                                      String(pa.getPassword()));
                return pa;
            }
          });
    BufferedReader in = null;
    StringBuffer sb = new StringBuffer();

    try {
        URL url = new URL(strURL);
        URLConnection connection = url.openConnection();
        in = new BufferedReader(new InputStreamReader(connection
                .getInputStream()));

        String line;

        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
    } catch (java.net.ProtocolException e) {
        sb.append("User Or Password is wrong!");
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (Exception e) {
            System.out.println("Exception");
        }
    }

    Log.d("DATA", sb.toString());

}       
    }
于 2012-12-13T05:14:26.673 回答