您的位置:首页 > 移动开发

第四次团队作业:社团申请App

2017-12-19 21:05 218 查看
概要:

基于上次软件设计本着界面简洁、易于使用的初衷,进行功能的实现,代码位置: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));
}
}


  

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: