編輯:Android開發實例
創建RegActivity
客戶端建立:
HttpURL url = new HttpURL();
// url地址
String requestUrl = "http://10.0.2.2:8080/web/servlet/RegServlet";
// 參數,跟數據庫傳入數據結合,藍色字相當於哈希表索引,可以隨便定義,無實際意義,但要和客戶端接口實現相同命名
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("userName", loginName);
requestParams.put("userPass", pass);
requestParams.put("sex", sex);
requestParams.put("city", ct);
requestParams.put("job", job);
requestParams.put("marry", ma);
requestParams.put("love", love);
// 獲取登錄用戶信息,定死的
InputStream ins = url.getHttpCon(requestUrl, requestParams);
XStream xStream = new XStream();
UserInfo user = (UserInfo)xStream.fromXML(ins);
url中”servlet/RegServlet”為獲得的
客戶端上網條件設置:
在相同界面添加Activity頁面注冊:(最標准的情況應該在創建RegActivity時,同時創建)
在服務器和客戶端分別建立相同的包,並在包下建立相同的接口類
工程下建立已經封裝好的HttpURL
服務器下建立與RegActivity相應的RegServlet連接
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//賬號
String username = request.getParameter("userName");
//密碼
String userpass = request.getParameter("userPass");
String sex = request.getParameter("sex");
String city = request.getParameter("city");
String job = request.getParameter("job");
String marrage = request.getParameter("marry");
String love = request.getParameter("love");
//數據訪問
UserInfoDAO dao = new UserInfoDAO();
//創建user
UserInfo userInfo = new UserInfo();
userInfo.setUserName(username);
userInfo.setUserPass(userpass);
userInfo.setSex(sex);
userInfo.setCity(city);
userInfo.setJob(job);
userInfo.setMarry(marrage);
userInfo.setLove(love);
UserInfo user = dao.add(userInfo);
UserInfo user1 = dao.reId(user);
//生成xml
XStream xStream = new XStream();
System.out.println(xStream.toXML(user1));
PrintWriter out = response.getWriter();
out.print(xStream.toXML(user1));
out.flush();
out.close();
}
上圖與數據庫交互的Dao類也要相應的建立。
工程下建立已經封裝好的HttpURL
服務器下建立與RegActivity相應的RegServlet連接
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//賬號
String username = request.getParameter("userName");
//密碼
String userpass = request.getParameter("userPass");
String sex = request.getParameter("sex");
String city = request.getParameter("city");
String job = request.getParameter("job");
String marrage = request.getParameter("marry");
String love = request.getParameter("love");
//數據訪問
UserInfoDAO dao = new UserInfoDAO();
//創建user
UserInfo userInfo = new UserInfo();
userInfo.setUserName(username);
userInfo.setUserPass(userpass);
userInfo.setSex(sex);
userInfo.setCity(city);
userInfo.setJob(job);
userInfo.setMarry(marrage);
userInfo.setLove(love);
UserInfo user = dao.add(userInfo);
UserInfo user1 = dao.reId(user);
//生成xml
XStream xStream = new XStream();
System.out.println(xStream.toXML(user1));
PrintWriter out = response.getWriter();
out.print(xStream.toXML(user1));
out.flush();
out.close();
}
上圖與數據庫交互的Dao類也要相應的建立。
登錄應用程序的屏幕,詢問憑據登錄到一些特定的應用。可能需要登錄到Facebook,微博等本章介紹了,如何創建一個登錄界面,以及如何管理安全問題和錯誤嘗試。首先,必須定義兩
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用
我們在進行Android開發時往往需要訪問SD卡的內容,而且因為文件很多,希望
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用