第 3 篇 Scrum 衝刺部落格
阿新 • • 發佈:2018-12-21
各個成員今日完成的任務(如果完成的任務為開發或測試任務,需給出對應的Github程式碼簽入記錄截圖;如果完成的任務為調研任務,需給出對應的調研總結部落格連結;如果完成的任務為學習技術任務,需給出學習總結部落格連結)
陸大嶽彭霖:實現登入功能
參考Java Web的編寫實現了登入介面並登陸成功
import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; /** * 測試登入Servlet * * @author Implementist */ public class LoginServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 設定響應內容型別 response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); try (PrintWriter out = response.getWriter()) { //獲得請求中傳來的使用者名稱和密碼 String accountNumber = request.getParameter("AccountNumber").trim(); String password = request.getParameter("Password").trim(); //密碼驗證結果 Boolean verifyResult = verifyLogin(accountNumber, password); Map<String, String> params = new HashMap<>(); JSONObject jsonObject = new JSONObject(); if (verifyResult) { params.put("Result", "success"); } else { params.put("Result", "failed"); } jsonObject.put("params", params); out.write(jsonObject.toString()); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * 驗證使用者名稱密碼是否正確 * * @param userName * @param password */ private Boolean verifyLogin(String userName, String password) { User user = UserDAO.queryUser(userName); //賬戶密碼驗證 return null != user && password.equals(user.getPassword()); } }
public void LoginRequest(final String accountNumber, final String password) { //請求地址 String url = "http://59.110.141.197:8080/MyFirstWebAPP/LoginServlet"; //注① String tag = "Login"; //注② //取得請求佇列 RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); //防止重複請求,所以先取消tag標識的請求佇列 requestQueue.cancelAll(tag); //建立StringRequest,定義字串請求的請求方式為POST(省略第一個引數會預設為GET方式) final StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params"); //注③ String result = jsonObject.getString("Result"); //注④ if (result.equals("success")) { //注⑤ Toast.makeText(getApplicationContext(),"登入成功",Toast.LENGTH_LONG).show(); Intent intent = null; intent = new Intent(MainActivity.this,FunctionActivity.class); intent.putExtra("Username", username.getText().toString()); startActivity(intent); } else { Toast.makeText(getApplicationContext(),"賬號或密碼錯誤",Toast.LENGTH_LONG).show(); } } catch (JSONException e) { Toast.makeText(getApplicationContext(),"連線失敗",Toast.LENGTH_LONG).show(); Log.e("TAG", e.getMessage(), e); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //做自己的響應錯誤操作,如Toast提示(“請稍後重試”等) Log.e("TAG", error.getMessage(), error); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("AccountNumber", accountNumber); //注⑥ params.put("Password", password); return params; } }; //設定Tag標籤 request.setTag(tag); //將請求新增到佇列中 requestQueue.add(request); }
各個成員遇到的問題
- 問題1:登入失敗
- 解決方案:沒有配置LoginServlet的URL,應在web.xml中配置
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>chatask.LoginServlet</servlet-class>
</servlet>
明日各個成員的任務安排
陸大嶽、彭霖:編寫簽到功能
胡智韜:編寫簽到頁面
牛浩遠:寫第四篇部落格
•現階段團隊成員的貢獻任務量(h)分別是:
陸大嶽40
彭霖20
胡智韜0(未設計介面)
牛浩遠0(未寫部落格)