標籤:return try amr 審核 nal on() github net final
概要:
基於上次軟體設計本著介面簡潔、便於使用的初衷,進行功能的實現,代碼位置:https://github.com/LinZezhong/testDemo
第一部分:軟體的使用
註冊:
登入:
主介面(所有社團顯示):
點擊社團,將跳到社團申請頁面:
點擊申請加入,即可提交申請
如果申請過該部門,將會提示“已申請過了"
點擊主介面”個人“,查看修改個人資訊
點擊主介面”審核“,顯示自己有許可權審核的社團部門
點擊相應部門,出現相應需要處理的部門申請:
點擊,
點提交,完成該申請的審核
此時,201521121076使用者點擊”我的申請“,查看自己的申請
點擊,出現自己的申請結果及通知
第二部分:代碼實現(採用http資料轉送)
用戶端採用的是Eclipse編輯
結構如下:
伺服器端被我架設在雲端服務器上,使用MyEclipse+Tomcat+MySQL
MyEclipse:
思路:根據用戶端的不同功能要求串連到伺服器端的不同servlet上,有servlet調用相應的MySQL操作方法獲得相應的資料,分裝成JSON資料轉送到用戶端。
用戶端:
使用UrlConnection以post方式向伺服器端發送請求。
要求方法:
public class GetPostUtil {public static final String urlBase="http://111.230.230.93:8080/LinkMySQL/servlet/";public static String sendPost(String url,String params){PrintWriter out = null;BufferedReader in = null;String json=null;try {URL realUrl = new URL(url);URLConnection conn = realUrl.openConnection();//設定通用的請求屬性conn.setRequestProperty("accept","*/*");conn.setRequestProperty("connecttion","Keep-Alive");conn.setRequestProperty("user-agent","Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.1;SV1)");//發送post請求必須設定的兩行conn.setDoOutput(true);conn.setDoInput(true);//擷取URLConnection對象對應的輸出資料流out = new PrintWriter(conn.getOutputStream());//發送請求參數out.print(params);//flush緩衝流的緩衝out.flush();//定義BufferdReader輸入資料流來讀取URL的響應in = new BufferedReader(new InputStreamReader(conn.getInputStream()));InputStream is = conn.getInputStream();json = netUtil.readString(is);return json;} catch (Exception e) {System.out.println("發送post請求出現異常!"+e);e.printStackTrace();}finally{try{if(out !=null){out.close();}if(in != null){in.close();}}catch(IOException e){e.printStackTrace();}}return json;}}
伺服器回傳的資料轉化為json字串方法:
public class netUtil {public static byte[] readBytes(InputStream is){try { byte[] buffer = new byte[1024]; int len = -1 ; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while((len = is.read(buffer)) != -1){ baos.write(buffer, 0, len); } baos.close(); return baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null ;}public static String readString(InputStream is){return new String(readBytes(is));}}
第四次團隊作業:社團申請App