第四次團隊作業:社團申請App

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.