团队博客

团队项目有变,由原课题改为了云相册。

联网登录注册部分代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
    System.out.println("---get---");  
    this.doPost(request, response);  
}  
  
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      //   
      

request.setCharacterEncoding("UTF-8"); String loginName = request.getParameter("LoginName"); String loginPassWord = request.getParameter("LoginPassWord"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = null; DataOutputStream output = new DataOutputStream(response.getOutputStream()); try{ out = response.getWriter(); if(loginName.equals("sun") && loginPassWord.equals("011")) { output.writeUTF("server data: success!"); output.writeInt(1); } else { //wrong output.writeUTF("server data: fail!"); out.print("failed"); } } finally { if(out != null) out.close(); if(output != null) output.close(); } }
import java.lang.ref.WeakReference;  
  
import com.example.mapsun.LoginActivity;  
  
import android.app.Activity;  
import android.app.ProgressDialog;  
import android.os.AsyncTask;  
  
public class LoginAsyncTask extends AsyncTask<Object, Object, Object> {  
  
    boolean result = true;  
    String g_loginName, g_loginPassword;  
    private final WeakReference<Activity> mActivity;  
    private static ProgressDialog dialog;  
      
    public LoginAsyncTask(LoginActivity activity, String loginName, String loginPassword)  
    {  
        g_loginName = loginName;  
        g_loginPassword = loginPassword;  
        mActivity = new WeakReference<Activity>(activity);  
    }  
      
    @Override    
    protected void onPreExecute() {    
        if(null == dialog){  
            dialog = new ProgressDialog(mActivity.get());  
        }  
        dialog.setTitle("please wait");  
        dialog.setMessage("Logining...");  
        dialog.setCancelable(false);  
        dialog.show();  
    }    
      
  
  
  
    @Override  
    protected Object doInBackground(Object... arg0) {  
        // TODO Auto-generated method stub  
        UserService userServ  = new UserServiceImpl();  
        try {  
            result = userServ.userLogin(g_loginName, g_loginPassword);  
        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        return result;  
    }  

    protected void onPostExecute(Object result) {  
          
        String strMsg;  
        if(result.equals(true))  
        {  
            strMsg = "success";  
        }  
        else  
            strMsg = "failed";  
        ((LoginActivity)mActivity.get()).ShowTip(strMsg);  
        dialog.cancel();  
    }  
}  
public class UserServiceImpl implements UserService {  
  
    private static final String TAG = "UserServiceImplement";  
      
    @Override  
    public boolean userLogin(String loginName, String loginPassword)  
            throws Exception {  
        // TODO Auto-generated method stub  
          
          
        String result;  
        HttpPost httpPost = new HttpPost(UriAPI.HTTPCustomer);  
          
        List<NameValuePair> params = new ArrayList<NameValuePair>();  
        params.add(new BasicNameValuePair("LoginName", loginName));  
        params.add(new BasicNameValuePair("LoginPassWord", loginPassword));  
          
        try{  
            httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));  
            HttpResponse httpResp = new DefaultHttpClient().execute(httpPost);  
            if (httpResp.getStatusLine().getStatusCode()==200) {  
                             byte[] data =new byte[2048];  
                             data =EntityUtils.toByteArray((HttpEntity)httpResp.getEntity());  
                             ByteArrayInputStream bais = new ByteArrayInputStream(data);  
                             DataInputStream dis = new DataInputStream(bais);  
                             result=new String(dis.readUTF());  
                                  Log.i("service result:", result);  
                             return true;  
            }  
              
        }catch(ClientProtocolException e){    
            e.printStackTrace();    
        }catch(UnsupportedEncodingException e){    
            e.printStackTrace();    
        } catch (IOException e) {    
            e.printStackTrace();    
        }    
        return false;  
    }  
      
  
    public class UriAPI{  
        public static final String HTTPCustomer = "地址";  
    }  
}  

 

posted @ 2021-04-22 22:29  谦寻  阅读(49)  评论(0编辑  收藏  举报