├── src ├── conf │ ├── dbip.properties │ ├── dbip_backup.properties │ ├── db_backup.properties │ └── db.properties ├── utility │ ├── PageBean.java │ ├── MD5Util.java │ ├── LogEvent.java │ └── FileUpload.java ├── register │ ├── dao │ │ └── SignUp.java │ └── file │ │ └── ServletAction.java ├── user │ ├── dao │ │ ├── FileDao.java │ │ └── UserFile.java │ └── file │ │ └── ServletAction.java ├── common │ ├── ForgetSecret.java │ └── LoginServlet.java ├── dao │ ├── FB_db.java │ └── FB_id.java └── flight │ ├── file │ ├── OrderAction.java │ └── ServletAction.java │ └── dao │ ├── FlightFile.java │ └── FileDao.java ├── logout.jsp ├── index.jsp ├── scripts ├── login.js ├── user_list.js └── ticket_list.js ├── user_list.jsp ├── tickets_list.jsp ├── modify-password.html ├── forget-password.html ├── signup.html ├── homepage.jsp ├── user-info.jsp ├── ticket_add_div.jsp └── ticket_modify_div.jsp /src/conf/dbip.properties: -------------------------------------------------------------------------------- 1 | #dbip.properties 2 | #Wed Jan 10 11:48:51 CST 2007 3 | IP=localhost -------------------------------------------------------------------------------- /src/conf/dbip_backup.properties: -------------------------------------------------------------------------------- 1 | #dbip_backup.properties 2 | #Wed Jan 10 11:48:51 CST 2007 3 | IP=localhost -------------------------------------------------------------------------------- /logout.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | 3 | <% 4 | session.removeAttribute("userID"); 5 | session.setAttribute("login_status",0); 6 | %> 7 | 10 | -------------------------------------------------------------------------------- /src/conf/db_backup.properties: -------------------------------------------------------------------------------- 1 | #db_backup.properties 2 | #Sun Jul 30 20:37:57 CST 2006 3 | DRIVER=com.mysql.jdbc.Driver 4 | USERNAME=root 5 | PASSWD=woaizhoujielun 6 | URL1=jdbc:mysql:// 7 | URL2=user=root&password=woaizhoujielun&useUnicode=true&characterEncoding=UTF-8 8 | debuglevel=1 -------------------------------------------------------------------------------- /index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: CheneyWu 4 | Date: 2018/11/1 5 | Time: 下午3:32 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 13 | -------------------------------------------------------------------------------- /src/conf/db.properties: -------------------------------------------------------------------------------- 1 | #db.properties 2 | #Sun Jul 30 20:37:57 CST 2006 3 | DRIVER=com.mysql.jdbc.Driver 4 | USERNAME=root 5 | PASSWD=woaizhoujielun 6 | URL1=jdbc:mysql:// 7 | URL2=user=root&password=woaizhoujielun&useUnicode=true&characterEncoding=UTF-8 8 | 9 | username=root 10 | password=woaizhoujielun 11 | 12 | debuglevel=1 -------------------------------------------------------------------------------- /src/utility/PageBean.java: -------------------------------------------------------------------------------- 1 | package utility; 2 | 3 | public class PageBean { 4 | 5 | private int page; // 第几页 6 | private int rows; // 每页的记录数 7 | private int start; // 起始页 8 | 9 | public PageBean(int page, int rows) { 10 | super(); 11 | this.page = page; 12 | this.rows = rows; 13 | } 14 | public int getPage() { 15 | return page; 16 | } 17 | public void setPage(int page) { 18 | this.page = page; 19 | } 20 | public int getRows() { 21 | return rows; 22 | } 23 | public void setRows(int rows) { 24 | this.rows = rows; 25 | } 26 | 27 | public int getStart() { 28 | return (page-1)*rows; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/utility/MD5Util.java: -------------------------------------------------------------------------------- 1 | package utility; 2 | 3 | import java.security.MessageDigest; 4 | 5 | public class MD5Util { 6 | public final static String MD5(String s) { 7 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 8 | try { 9 | byte[] btInput = s.getBytes(); 10 | // 获得MD5摘要算法的 MessageDigest 对象 11 | MessageDigest mdInst = MessageDigest.getInstance("MD5"); 12 | // 使用指定的字节更新摘要 13 | mdInst.update(btInput); 14 | // 获得密文 15 | byte[] md = mdInst.digest(); 16 | // 把密文转换成十六进制的字符串形式 17 | int j = md.length; 18 | char str[] = new char[j * 2]; 19 | int k = 0; 20 | for (int i = 0; i < j; i++) { 21 | byte byte0 = md[i]; 22 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 23 | str[k++] = hexDigits[byte0 & 0xf]; 24 | } 25 | return new String(str); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | return null; 29 | } 30 | } 31 | 32 | private static String byteArrayToHexString(byte b[]) { 33 | StringBuffer resultSb = new StringBuffer(); 34 | for (int i = 0; i < b.length; i++) 35 | resultSb.append(byteToHexString(b[i])); 36 | return resultSb.toString(); 37 | } 38 | 39 | private static String byteToHexString(byte b) { 40 | int n = b; 41 | if (n < 0) 42 | n += 256; 43 | int d1 = n / 16; 44 | int d2 = n % 16; 45 | return hexDigits[d1] + hexDigits[d2]; 46 | } 47 | 48 | public static String MD5Encode(String origin, String charsetname) { 49 | String resultString = null; 50 | try { 51 | resultString = new String(origin); 52 | MessageDigest md = MessageDigest.getInstance("MD5"); 53 | if (charsetname == null || "".equals(charsetname)) 54 | resultString = byteArrayToHexString(md.digest(resultString.getBytes())); 55 | else 56 | resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname))); 57 | } catch (Exception exception) { 58 | } 59 | return resultString; 60 | } 61 | 62 | private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; 63 | 64 | public static void main(String[] args) { 65 | System.out.println(MD5Util.MD5("20121221")); 66 | System.out.println(MD5Util.MD5("加密")); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/utility/LogEvent.java: -------------------------------------------------------------------------------- 1 | package utility; 2 | 3 | /* 4 | * 调用步骤: 5 | * 1.import security.include.LogEvent; 6 | * 2.LogEvent log=new LogEvent(session); 7 | * 3.log.log("某某信息"); 8 | * 4.或者:log.log("某某信息","某某操作"); 9 | * 5.或者:log.log("某某信息","某某操作",1); 10 | */ 11 | import java.text.SimpleDateFormat; 12 | import dao.FB_db; 13 | import javax.servlet.ServletContext; 14 | import javax.servlet.http.HttpSession; 15 | 16 | public class LogEvent { 17 | HttpSession session = null; 18 | String userId=""; 19 | String time=""; 20 | String ip=""; 21 | 22 | public LogEvent() { 23 | } 24 | 25 | public LogEvent(HttpSession session) { 26 | this.session = session; 27 | getClientInformation(); 28 | } 29 | public void setSession(HttpSession session) throws Exception { 30 | try { 31 | this.session = session; 32 | getClientInformation(); 33 | } catch (Exception e) { 34 | System.out.println("初始化Bean出现错误!" + e.getMessage()); 35 | } 36 | } 37 | public void getClientInformation(){ 38 | ip=(String)session.getAttribute("ip"); 39 | userId=(String)session.getAttribute("user_name"); 40 | time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()); 41 | } 42 | public void log(String msg) { 43 | try { 44 | log(msg, "未定义操作"); 45 | } catch (Exception e) { 46 | System.out.println("log出现错误!" + e.getMessage()); 47 | } 48 | } 49 | 50 | public void log(String msg, String operation) { 51 | log(msg, operation,"security"); 52 | } 53 | public void log(String msg, String operation,String module) { 54 | String time = ""; 55 | String operator = (String) session.getAttribute("user_id"); 56 | java.util.Date now = new java.util.Date(); 57 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 58 | time = formatter.format(now); 59 | int type=0; 60 | try { 61 | ServletContext dbApplication = session.getServletContext(); 62 | FB_db log_db = new FB_db((String) session.getAttribute("unit_db_name")); 63 | String sql = "insert into public_log(colTime,colType,colContent,colOperation,colUserId,colModule) values(" + "'" + time + "'" + "," + type + "" + ",'" + msg + "'" + ",'" + operation + "'" + ",'" + operator + "'" + ",'"+module+"')"; 64 | int result = log_db.executeUpdate(sql); 65 | log_db.close(); 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/register/dao/SignUp.java: -------------------------------------------------------------------------------- 1 | package register.dao; 2 | 3 | public class SignUp { 4 | //数据库字段 5 | private String userName; 6 | private String userPsd; 7 | private String userID; 8 | private String userCard; 9 | private String userAge; 10 | private String userPlace; 11 | 12 | //向数据库传数据 13 | private String action; 14 | private String dbName="FlightBooking"; 15 | private String tableName; 16 | private String type=""; 17 | private String userType=""; 18 | 19 | public SignUp(){ } 20 | 21 | public String getUserName() { 22 | return userName; 23 | } 24 | public void setUserName(String userName) { 25 | this.userName = userName; 26 | } 27 | 28 | public String getUserPsd() { return userPsd; } 29 | public void setUserPsd(String userPsd) { 30 | this.userPsd = userPsd; 31 | } 32 | 33 | public String getUserID() { 34 | return userID; 35 | } 36 | public void setUserID(String userID) { 37 | this.userID = userID; 38 | } 39 | 40 | public String getUserCard() { 41 | return userCard; 42 | } 43 | public void setUserCard(String userCard) { 44 | this.userCard = userCard; 45 | } 46 | 47 | public String getUserAge() { 48 | return userAge; 49 | } 50 | public void setUserAge(String userAge) { 51 | this.userAge = userAge; 52 | } 53 | 54 | public String getUserPlace() { 55 | return userPlace; 56 | } 57 | public void setUserPlace(String userPlace) { 58 | this.userPlace = userPlace; 59 | } 60 | 61 | public String getDbName() { 62 | return dbName; 63 | } 64 | public void setDbName(String dbName) { this.dbName = dbName; } 65 | 66 | public String getAction() { 67 | return action; 68 | } 69 | public void setAction(String action) { this.action = action; } 70 | 71 | public String getTableName() { 72 | return tableName; 73 | } 74 | public void setTableName(String tableName) { 75 | this.tableName = tableName; 76 | } 77 | 78 | public String getType() { return type; } 79 | public void setType(String type) { 80 | this.type = type; 81 | } 82 | 83 | public String getUserType() { 84 | return userType; 85 | } 86 | public void setUserType(String userType) { 87 | this.userType = userType; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/user/dao/FileDao.java: -------------------------------------------------------------------------------- 1 | package user.dao; 2 | import java.io.IOException; 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | 11 | import dao.FB_db; 12 | 13 | public class FileDao { 14 | /* 15 | * 功能:返回结果集 16 | */ 17 | public JSONObject getRecord(UserFile query) throws SQLException, IOException, JSONException { 18 | //开始查询数据库 19 | String resultMsg="ok"; 20 | int resultCode=0; 21 | List jsonList = new ArrayList(); 22 | try { 23 | FB_db query_db = new FB_db(query.getDbName()); 24 | //构造sql语句,根据传递过来的查询条件参数 25 | String sql="select * from order_info inner join ticket_info where order_info.flightID=ticket_info.flightID and order_info.srcDate=ticket_info.srcDate and userID=" + query.getUserID(); 26 | int count=0; 27 | ResultSet rs = query_db.executeQuery(sql); 28 | while (rs.next()) { 29 | List list = new ArrayList(); 30 | list.add(rs.getString("userID")); 31 | list.add(rs.getString("orderID")); 32 | list.add(rs.getString("flightID")); 33 | list.add(rs.getString("srcDate")); 34 | list.add(rs.getString("srcTime")); 35 | list.add(rs.getString("valid")); 36 | list.add(rs.getString("used")); 37 | list.add(rs.getString("price")); 38 | list.add(count); 39 | count=count+1; //做上下记录导航用 40 | jsonList.add(list); 41 | } 42 | rs.close(); 43 | query_db.close(); 44 | } catch (SQLException sqlexception) { 45 | sqlexception.printStackTrace(); 46 | resultCode=10; 47 | resultMsg="查询数据库出现错误!"+sqlexception.getMessage(); 48 | } 49 | //jsonList.clear(); 50 | //下面开始构建返回的json 51 | JSONObject jsonObj=new JSONObject(); 52 | jsonObj.put("aaData",jsonList); 53 | jsonObj.put("result_msg",resultMsg);//如果发生错误就设置成"error"等 54 | jsonObj.put("result_code",resultCode);//返回0表示正常,不等于0就表示有错误产生,错误代码 55 | return jsonObj; 56 | } 57 | 58 | public JSONObject deleteRecord(String dbName,String orderID) throws JSONException, SQLException{ 59 | String tableName="order_info"; 60 | FB_db query_db = new FB_db(dbName); 61 | String sql="update "+tableName+" set valid=0 where orderID="+orderID; 62 | int result = query_db.executeUpdate(sql); 63 | System.out.println(sql); 64 | query_db.close(); 65 | //下面开始构建返回的json 66 | JSONObject jsonObj=new JSONObject(); 67 | jsonObj.put("result_msg","OK");//如果发生错误就设置成"error"等 68 | jsonObj.put("result_code",result);//返回0表示正常,不等于0就表示有错误产生,错误代码 69 | return jsonObj; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /scripts/login.js: -------------------------------------------------------------------------------- 1 | window.onload=function(){ 2 | checkCookie(); 3 | $.ajax({ 4 | type: "get", 5 | url: 'common_login_servlet?source=sign-in', 6 | dataType: 'json', 7 | success: function (json) { 8 | if(json.login_status == 1) 9 | { 10 | DisplayIcon(1); 11 | } 12 | } 13 | }); 14 | } 15 | 16 | function signin() { 17 | // form.action = "common_login_servlet"; 18 | //form.submit(); 19 | var psd = $("#password").val(); 20 | var phone = $("#phone").val(); 21 | var src = "sign-in"; 22 | $.ajax({ 23 | type: "post", 24 | url: 'common_login_servlet', 25 | data: {source:src, userPsd: psd, userID: phone}, 26 | dataType: 'json', 27 | success: function (data) { 28 | //alert(JSON.stringify(data)); 29 | var flag = data.flag; 30 | DisplayIcon(flag); 31 | }, 32 | error: function (XMLHttpRequest, textStatus) { 33 | alert(XMLHttpRequest.status); 34 | alert(XMLHttpRequest.readyState); 35 | alert(textStatus); 36 | } 37 | }); 38 | } 39 | 40 | $("#checkbox").click(function(){ 41 | if(this.checked) { 42 | if (($("#phone").val() == "") || ($("#password").val() == "")) { 43 | //alert("请输入账号和密码!"); 44 | }else{ 45 | var userID=$("#phone").val(); 46 | var userPsd=$("#password").val(); 47 | setCookie("userID",userID,30); 48 | setCookie("password",userPsd,30); 49 | setCookie("remember",true,30); 50 | } 51 | }else{ 52 | clearCookie("username"); 53 | clearCookie("password"); 54 | clearCookie("remember"); 55 | } 56 | }); 57 | var clearCookie=function(name){ 58 | setCookie(name, "", -1); 59 | }; 60 | var getCookie=function(name){ 61 | if (document.cookie.length>0) 62 | { 63 | c_start=document.cookie.indexOf(name + "=") 64 | if (c_start!=-1) 65 | { 66 | c_start=c_start + name.length+1 67 | c_end=document.cookie.indexOf(";",c_start) 68 | if (c_end==-1) c_end=document.cookie.length 69 | return unescape(document.cookie.substring(c_start,c_end)) 70 | } 71 | } 72 | return "" 73 | }; 74 | var setCookie=function(name,value,expiredays){ 75 | var exdate=new Date(); 76 | exdate.setDate(exdate.getDate()+expiredays); 77 | document.cookie=name+ "=" +escape(value)+ 78 | ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); 79 | }; 80 | var checkCookie=function(){ 81 | var userID=getCookie('userID'); 82 | var userPsd=getCookie('password'); 83 | var remember=getCookie('remember'); 84 | if(remember){ 85 | $('#uniform-checkbox span').addClass("checked"); 86 | if (userID!=null && userID!="") 87 | {$("#phone").val(userID);}else{} 88 | if (userPsd!=null && userPsd!="") 89 | {$("#password").val(userPsd);}else{} 90 | } 91 | }; 92 | -------------------------------------------------------------------------------- /src/common/ForgetSecret.java: -------------------------------------------------------------------------------- 1 | package common; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | import dao.FB_db; 7 | import utility.LogEvent; 8 | 9 | import java.io.IOException; 10 | import java.io.PrintWriter; 11 | import java.sql.*; 12 | import java.text.SimpleDateFormat; 13 | import java.util.Date; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServlet; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import javax.servlet.http.HttpSession; 20 | 21 | public class ForgetSecret extends HttpServlet { 22 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 23 | try { 24 | getRecord(request,response); 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | public void getRecord(HttpServletRequest request, HttpServletResponse response) throws SQLException { 30 | /*用户注册信息*/ 31 | String resultMsg="OK"; 32 | int resultCode=0; 33 | System.out.println("获取用户ID"); 34 | String userID = request.getParameter("userID"); 35 | String userCard = request.getParameter("userCard"); 36 | String userPsd = request.getParameter("userPsd"); 37 | try { 38 | FB_db query_db = new FB_db("FlightBooking"); //建立与数据库交互变量 39 | String sql = "select userID from user_info where userID='"+ userID + "' and userCard='"+ userCard+"'"; 40 | String sql2 = "UPDATE user_info SET userPsd='"+userPsd+"' WHERE userID='"+userID+"'"; 41 | ResultSet rs = query_db.executeQuery(sql); 42 | if(rs.next()){ 43 | System.out.println(userID); 44 | System.out.println(rs.getString("userID")); 45 | int result = query_db.executeUpdate(sql2); 46 | try { 47 | JSONObject jsonObj=new JSONObject(); 48 | try { 49 | jsonObj.put("flag",result); 50 | } catch (JSONException e) { 51 | e.printStackTrace(); 52 | } 53 | response.setContentType("application/json; charset=UTF-8"); 54 | PrintWriter out; 55 | out = response.getWriter(); 56 | out.print(jsonObj); 57 | System.out.println(jsonObj.toString()); 58 | System.out.println("写入成功"); 59 | out.flush(); 60 | out.close(); 61 | } catch (IOException e) { 62 | e.printStackTrace(); 63 | } 64 | /*SmsBase msg = new SmsBase(); 65 | msg.setMoblie(userID); 66 | msg.setValidID("123456"); 67 | msg.sendMsg();*/ 68 | } 69 | rs.close(); 70 | query_db.close(); 71 | }catch (SQLException sqlexception) { 72 | sqlexception.printStackTrace(); 73 | resultCode=10; 74 | resultMsg="查询数据库出现错误!"+sqlexception.getMessage(); 75 | } 76 | 77 | } 78 | 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /user_list.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | <% 4 | String orderID = request.getParameter("orderID"); 5 | String existResultset = request.getParameter("exist_resultset"); 6 | %> 7 | 8 | 9 | 10 | 11 | 12 | 用户订单 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 54 | 55 | 56 | 57 |
58 |
59 |
60 | 61 | 64 | 65 | 68 |
69 |
70 |
71 |
72 | 73 | 74 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/register/file/ServletAction.java: -------------------------------------------------------------------------------- 1 | package register.file; 2 | import dao.FB_db; 3 | import dao.FB_id; 4 | 5 | import java.io.*; 6 | import java.io.IOException; 7 | import java.io.PrintWriter; 8 | import java.io.UnsupportedEncodingException; 9 | import java.sql.Connection; 10 | import java.sql.ResultSet; 11 | import java.sql.SQLException; 12 | import java.text.SimpleDateFormat; 13 | import java.util.ArrayList; 14 | import java.util.Date; 15 | import java.util.Iterator; 16 | import java.util.List; 17 | 18 | import javax.servlet.ServletException; 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | import javax.servlet.http.HttpSession; 23 | 24 | import org.jfree.chart.ChartFactory; 25 | import org.jfree.chart.JFreeChart; 26 | import org.jfree.chart.plot.PlotOrientation; 27 | import org.jfree.chart.servlet.ServletUtilities; 28 | import org.jfree.data.DefaultCategoryDataset; 29 | import org.jfree.data.DefaultPieDataset; 30 | import org.json.JSONArray; 31 | import org.json.JSONException; 32 | import org.json.JSONObject; 33 | 34 | import utility.LogEvent; 35 | import utility.MD5Util; 36 | import register.dao.SignUp; 37 | public class ServletAction extends HttpServlet { 38 | SignUp su = new SignUp(); 39 | public String module = "flight"; 40 | public String sub = "file"; 41 | public LogEvent flightLog = new LogEvent(); 42 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 43 | try { 44 | getRecord(request,response); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | public void getRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 50 | /*用户注册信息*/ 51 | String userName = request.getParameter("userName"); 52 | String userPsd = request.getParameter("userPsd"); 53 | String userID = request.getParameter("userID"); 54 | String userCard = request.getParameter("userCard"); 55 | String userAge = request.getParameter("userAge"); 56 | String userPlace = request.getParameter("userPlace"); 57 | su.setUserName(userName); 58 | su.setUserPsd(userPsd); 59 | su.setUserID(userID); 60 | su.setUserCard(userCard); 61 | su.setUserAge(userAge); 62 | su.setUserPlace(userPlace); 63 | System.out.println(userName); 64 | System.out.println(userPsd); 65 | System.out.println(userID); 66 | System.out.println(userCard); 67 | System.out.println(userAge); 68 | System.out.println(userPlace); 69 | System.out.println(su.getDbName()); 70 | FB_db insert_db = new FB_db(su.getDbName()); //建立与数据库交互变量 71 | String sql = "insert into user_info(userID,username,userPsd,userAge,userPlace,userCard,userRole) " + 72 | "values('"+su.getUserID()+"','"+su.getUserName()+"','"+su.getUserPsd()+"','"+su.getUserAge()+ 73 | "','"+ su.getUserPlace()+"','"+su.getUserCard()+"','normal')"; 74 | int result = insert_db.executeUpdate(sql); 75 | try { 76 | JSONObject jsonObj=new JSONObject(); 77 | try { 78 | jsonObj.put("result",result); 79 | } catch (JSONException e) { 80 | e.printStackTrace(); 81 | } 82 | response.setContentType("application/json; charset=UTF-8"); 83 | PrintWriter out; 84 | out = response.getWriter(); 85 | out.print(jsonObj); 86 | System.out.println(jsonObj.toString()); 87 | System.out.println("写入成功"); 88 | out.flush(); 89 | out.close(); 90 | } catch (IOException e) { 91 | e.printStackTrace(); 92 | } 93 | insert_db.close(); 94 | //response.sendRedirect("homepage.jsp"); 95 | } 96 | 97 | 98 | } -------------------------------------------------------------------------------- /src/dao/FB_db.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.io.*; 4 | import java.sql.*; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | import java.util.Properties; 8 | 9 | //链接到指定数据库 10 | public class FB_db { 11 | private Connection a; 12 | private Statement statement; 13 | private String drivername; 14 | private String database; 15 | private String url1; 16 | private String url2; 17 | private Integer debugLevel=1; 18 | 19 | public FB_db(String s) {//传数据库名 20 | getProperty(); //传入参数,给url1, url2, drivername赋值 21 | database = s; 22 | String s1 = url1 + s + "?" + url2; 23 | //jdbc:mysql://localhost:3306/FlightBooking?user=root&password=woaizhoujielun&useUnicode=true&characterEncoding=UTF-8 24 | String s2 = drivername; 25 | //com.mysql.jdbc.Driver 26 | try { 27 | Class.forName(s2); 28 | } catch (ClassNotFoundException classnotfoundexception) { 29 | classnotfoundexception.printStackTrace(); 30 | } 31 | try { 32 | a = DriverManager.getConnection(s1);//连接数据库 33 | statement = a.createStatement(); 34 | } catch (SQLException sqlexception) { 35 | sqlexception.printStackTrace(); 36 | } 37 | } 38 | 39 | //关闭数据库 40 | public void close() { 41 | try { 42 | statement.close(); 43 | a.close(); 44 | } catch (SQLException sqlexception) { 45 | sqlexception.printStackTrace(); 46 | } 47 | } 48 | 49 | //执行sql查询操作 50 | public ResultSet executeQuery(String s) { 51 | ResultSet resultset = null; 52 | try { 53 | if(debugLevel>0){ 54 | System.out.println("["+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())+"]"+"FB_db executeQuery:" + s); 55 | } 56 | resultset = statement.executeQuery(s); 57 | } catch (SQLException sqlexception) { 58 | sqlexception.printStackTrace(); 59 | } 60 | return resultset; 61 | } 62 | 63 | //执行sql更新操作 64 | public int executeUpdate(String s) { 65 | int resultset = 0; 66 | try { 67 | if(debugLevel>0){ 68 | System.out.println("["+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())+"]"+"FB_db executeUpdate:" + s); 69 | } 70 | resultset = statement.executeUpdate(s); 71 | } catch (SQLException sqlexception) { 72 | sqlexception.printStackTrace(); 73 | } 74 | return resultset; 75 | } 76 | 77 | //获取db.properties和dbip.properties定义内容,传入数据库操作类FB_db的变量中 78 | //获取与数据库的连接 79 | public void getProperty() { 80 | Properties properties = new Properties(); 81 | Properties properties1 = new Properties(); 82 | try { 83 | InputStream inputstream = getClass().getClassLoader().getResourceAsStream("/conf/db.properties"); 84 | InputStream inputstream1 = getClass().getClassLoader().getResourceAsStream("/conf/dbip.properties"); 85 | properties.load(inputstream); 86 | properties1.load(inputstream1); 87 | if (inputstream != null) 88 | inputstream.close(); 89 | inputstream1.close(); 90 | } catch (IOException ex) { 91 | System.err.println("Open Propety File Error"); 92 | } 93 | drivername = properties.getProperty("DRIVER"); 94 | url1 = properties.getProperty("URL1") + properties1.getProperty("IP") + ":3306/"; 95 | url2 = properties.getProperty("URL2"); 96 | //调试级别 97 | String level = properties.getProperty("debuglevel"); 98 | if(level!=null){ 99 | debugLevel=Integer.parseInt(level); 100 | }else{ 101 | debugLevel=0; 102 | } 103 | } 104 | 105 | public String getTable() { 106 | return database; 107 | } 108 | public void setTable(String s) { 109 | database = s; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/dao/FB_id.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.sql.*; 4 | import java.text.SimpleDateFormat; 5 | import dao.FB_db; 6 | 7 | public class FB_id { 8 | public static String getId(String path, String dbase) { 9 | String file_path = ""; 10 | String mod = ""; 11 | String id = ""; 12 | if (path.indexOf("/classes/") != -1) { 13 | file_path = path.split("/classes/")[1].substring(0, path.split("/classes/")[1].length() - 1); 14 | mod = file_path.split("/")[0]; 15 | } else { 16 | file_path = path; 17 | mod = file_path.split("/")[0]; 18 | } 19 | try { 20 | FB_db erp_db = new FB_db(dbase); 21 | String sql = "select file_id from " + mod + "_tree where file_path='" + file_path + "'"; 22 | ResultSet rs = erp_db.executeQuery(sql); 23 | if (rs.next()) { 24 | id = rs.getString("file_id"); 25 | id = id + "000000"; 26 | id = id.substring(0, 6); 27 | int filenum_temp = readTime(dbase, file_path); 28 | writeTime(dbase, file_path); 29 | String time = ""; 30 | java.util.Date now = new java.util.Date(); 31 | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 32 | time = formatter.format(now);// 获得当前时间 33 | id = id + time + filenum_temp + ""; 34 | } 35 | erp_db.close(); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | return id; 40 | } 41 | 42 | public static int readTime(String dbase, String file_path) { 43 | int filenum = 0; 44 | java.util.Date now = new java.util.Date(); 45 | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 46 | String time = formatter.format(now);// 获得当前时间 47 | 48 | FB_db erp_db = new FB_db(dbase); 49 | String kind_name = file_path.replaceAll("/", "_"); 50 | String kind = kind_name + "_" + time; 51 | try { 52 | String sql = "select * from security_counter where kind_name='" + kind_name + "'"; 53 | ResultSet rs = erp_db.executeQuery(sql); 54 | if (rs.next()) { 55 | if (kind.equals(rs.getString("kind"))) { 56 | filenum = Integer.parseInt(rs.getString("count_value")); 57 | } else { 58 | String sqla = "update security_counter set kind='" + kind + "', count_value='100001' where kind_name='" + kind_name + "'"; 59 | erp_db.executeUpdate(sqla); 60 | filenum = 100001; 61 | } 62 | } else { 63 | String sqla = "insert into security_counter(kind,count_value,kind_name) values ('" + kind + "','100001','" + kind_name + "')"; 64 | erp_db.executeUpdate(sqla); 65 | filenum = 100001; 66 | } 67 | erp_db.close(); 68 | } catch (Exception ex) { 69 | } 70 | return filenum; 71 | } 72 | 73 | public static void writeTime(String dbase, String file_path) { 74 | int filenum = 0; 75 | java.util.Date now = new java.util.Date(); 76 | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 77 | String time = formatter.format(now);// 获得当前时间 78 | 79 | FB_db erp_db = new FB_db(dbase); 80 | String kind_name = file_path.replaceAll("/", "_"); 81 | String kind = kind_name + "_" + time; 82 | try { 83 | String sql = "select * from security_counter where kind_name='" + kind_name + "'"; 84 | ResultSet rs = erp_db.executeQuery(sql); 85 | if (rs.next()) { 86 | filenum = Integer.parseInt(rs.getString("count_value")); 87 | filenum++; 88 | String sqla = "update security_counter set count_value='" + filenum + "' where kind_name='" + kind_name + "'"; 89 | erp_db.executeUpdate(sqla); 90 | } 91 | erp_db.close(); 92 | } catch (Exception ex) { 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/user/dao/UserFile.java: -------------------------------------------------------------------------------- 1 | package user.dao; 2 | 3 | public class UserFile { 4 | //数据库字段 5 | private String userID; 6 | private String orderID; 7 | private String flightID; 8 | private String srcDate; 9 | private String srcTime; 10 | private String valid; 11 | private String used; 12 | //传递条件查询用 13 | private String action; 14 | private String dbName; 15 | private String tableName=""; 16 | private String type=""; 17 | private String timeFrom=""; 18 | private String timeTo=""; 19 | private String timeSelect=""; 20 | private String groupId=""; 21 | private String groupSelect=""; 22 | private String timeInterval=""; 23 | private String statisticType=""; 24 | private String userName=""; 25 | public UserFile() { 26 | } 27 | 28 | public String getUserID() { 29 | return userID; 30 | } 31 | 32 | public void setUserID(String userID) { 33 | this.userID = userID; 34 | } 35 | 36 | public String getOrderID() { 37 | return orderID; 38 | } 39 | 40 | public void setOrderID(String orderID) { 41 | this.orderID = orderID; 42 | } 43 | 44 | public String getFlightID() { 45 | return flightID; 46 | } 47 | 48 | public void setFlightID(String flightID) { 49 | this.flightID = flightID; 50 | } 51 | 52 | public String getSrcDate() { 53 | return srcDate; 54 | } 55 | 56 | public void setSrcDate(String srcDate) { 57 | this.srcDate = srcDate; 58 | } 59 | 60 | public String getSrcTime() { 61 | return srcTime; 62 | } 63 | 64 | public void setSrcTime(String srcTime) { 65 | this.srcTime = srcTime; 66 | } 67 | 68 | public String getValid() { 69 | return valid; 70 | } 71 | 72 | public void setValid(String valid) { 73 | this.valid = valid; 74 | } 75 | 76 | public String getUsed() { 77 | return used; 78 | } 79 | 80 | public void setUsed(String used) { 81 | this.used = used; 82 | } 83 | 84 | public String getAction() { 85 | return action; 86 | } 87 | 88 | public void setAction(String action) { 89 | this.action = action; 90 | } 91 | 92 | public String getDbName() { 93 | return dbName; 94 | } 95 | 96 | public void setDbName(String dbName) { 97 | this.dbName = dbName; 98 | } 99 | 100 | public String getTableName() { 101 | return tableName; 102 | } 103 | 104 | public void setTableName(String tableName) { 105 | this.tableName = tableName; 106 | } 107 | 108 | public String getType() { 109 | return type; 110 | } 111 | 112 | public void setType(String type) { 113 | this.type = type; 114 | } 115 | 116 | public String getTimeFrom() { 117 | return timeFrom; 118 | } 119 | 120 | public void setTimeFrom(String timeFrom) { 121 | this.timeFrom = timeFrom; 122 | } 123 | 124 | public String getTimeTo() { 125 | return timeTo; 126 | } 127 | 128 | public void setTimeTo(String timeTo) { 129 | this.timeTo = timeTo; 130 | } 131 | 132 | public String getTimeSelect() { 133 | return timeSelect; 134 | } 135 | 136 | public void setTimeSelect(String timeSelect) { 137 | this.timeSelect = timeSelect; 138 | } 139 | 140 | public String getGroupId() { 141 | return groupId; 142 | } 143 | 144 | public void setGroupId(String groupId) { 145 | this.groupId = groupId; 146 | } 147 | 148 | public String getGroupSelect() { 149 | return groupSelect; 150 | } 151 | 152 | public void setGroupSelect(String groupSelect) { 153 | this.groupSelect = groupSelect; 154 | } 155 | 156 | public String getTimeInterval() { 157 | return timeInterval; 158 | } 159 | 160 | public void setTimeInterval(String timeInterval) { 161 | this.timeInterval = timeInterval; 162 | } 163 | 164 | public String getStatisticType() { 165 | return statisticType; 166 | } 167 | 168 | public void setStatisticType(String statisticType) { 169 | this.statisticType = statisticType; 170 | } 171 | 172 | public String getUserName() { 173 | return userName; 174 | } 175 | public void setUserName(String userName) { 176 | this.userName = userName; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/flight/file/OrderAction.java: -------------------------------------------------------------------------------- 1 | package flight.file; 2 | import dao.FB_db; 3 | import dao.FB_id; 4 | import flight.dao.FlightFile; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | import utility.LogEvent; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | import java.io.IOException; 15 | import java.io.PrintWriter; 16 | import java.sql.SQLException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.Date; 19 | 20 | public class OrderAction extends HttpServlet { 21 | FlightFile flightFile=new FlightFile(); 22 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 23 | try { 24 | getRecord(request,response); 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | public void getRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 30 | HttpSession session=request.getSession(); 31 | String userID=session.getAttribute("userID")==null?null:(String)session.getAttribute("userID"); 32 | if(userID == null){ 33 | try { 34 | JSONObject jsonObj=new JSONObject(); 35 | try { 36 | jsonObj.put("flag",0); 37 | } catch (JSONException e) { 38 | e.printStackTrace(); 39 | } 40 | response.setContentType("application/json; charset=UTF-8"); 41 | PrintWriter out; 42 | out = response.getWriter(); 43 | out.print(jsonObj); 44 | System.out.println(jsonObj.toString()); 45 | out.flush(); 46 | out.close(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | }else{ 51 | String orderID=request.getParameter("orderID"); 52 | String flightID=request.getParameter("flightID"); 53 | String srcDate=request.getParameter("srcDate"); 54 | String srcTime=request.getParameter("srcTime"); 55 | String valid=request.getParameter("valid"); 56 | String used=request.getParameter("used"); 57 | flightFile.setUserID(userID); 58 | flightFile.setDbName("FlightBooking"); 59 | flightFile.setOrderID(orderID); 60 | flightFile.setFlightID(flightID); 61 | flightFile.setSrcDate(srcDate); 62 | flightFile.setSrcTime(srcTime); 63 | flightFile.setValid(valid); 64 | flightFile.setUsed(used); 65 | System.out.println(userID); 66 | System.out.println(orderID); 67 | System.out.println(flightID); 68 | System.out.println(srcDate); 69 | System.out.println(srcTime); 70 | System.out.println(valid); 71 | System.out.println(used); 72 | FB_db insert_db = new FB_db(flightFile.getDbName()); //建立与数据库交互变量 73 | String sql = "insert into order_info(userID,orderID,flightID,srcDate,srcTime,valid,used) " + 74 | "values('"+flightFile.getUserID()+"','"+flightFile.getOrderID()+"','"+flightFile.getFlightID()+"','" +flightFile.getSrcDate()+ 75 | "','"+ flightFile.getSrcTime()+"','"+flightFile.getValid()+"','"+flightFile.getUsed()+"')"; 76 | int result = insert_db.executeUpdate(sql); 77 | insert_db.close(); 78 | 79 | try { 80 | JSONObject jsonObj=new JSONObject(); 81 | try { 82 | jsonObj.put("flag",result); 83 | } catch (JSONException e) { 84 | e.printStackTrace(); 85 | } 86 | response.setContentType("application/json; charset=UTF-8"); 87 | PrintWriter out; 88 | out = response.getWriter(); 89 | out.print(jsonObj); 90 | System.out.println(jsonObj.toString()); 91 | out.flush(); 92 | out.close(); 93 | } catch (IOException e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/user/file/ServletAction.java: -------------------------------------------------------------------------------- 1 | package user.file; 2 | /* 3 | * 待完成:用MVC模式分开DB和Action操作 4 | * 增删改查看导印统功能的实现 5 | */ 6 | import dao.FB_id; 7 | import dao.FB_db; 8 | 9 | import java.io.IOException; 10 | import java.io.PrintWriter; 11 | import java.io.UnsupportedEncodingException; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.text.SimpleDateFormat; 15 | import java.util.ArrayList; 16 | import java.util.Date; 17 | import java.util.Iterator; 18 | import java.util.List; 19 | 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import javax.servlet.http.HttpSession; 25 | 26 | import org.jfree.chart.ChartFactory; 27 | import org.jfree.chart.JFreeChart; 28 | import org.jfree.chart.plot.PlotOrientation; 29 | import org.jfree.chart.servlet.ServletUtilities; 30 | import org.jfree.data.DefaultCategoryDataset; 31 | import org.jfree.data.DefaultPieDataset; 32 | import org.json.JSONArray; 33 | import org.json.JSONException; 34 | import org.json.JSONObject; 35 | 36 | import user.dao.FileDao; 37 | import user.dao.UserFile; 38 | 39 | import utility.LogEvent; 40 | //import utility.MD5Util; 41 | public class ServletAction extends HttpServlet { 42 | //这里是需要改的,module和sub 43 | public String module = "user"; 44 | public String sub = "file"; 45 | 46 | public SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 47 | public LogEvent ylxLog = new LogEvent(); 48 | 49 | //处理顺序:先是service,后根据情况doGet或者doPost 50 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 51 | try { 52 | processAction(request,response); 53 | } catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | public void processAction(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 58 | request.setCharacterEncoding("UTF-8"); 59 | String action = request.getParameter("action"); 60 | boolean actionOk = false; 61 | showDebug("processAction收到的action是:"+action); 62 | if (action.equals("get_record")){ 63 | try { 64 | getRecord(request, response); 65 | } catch (SQLException e) { 66 | e.printStackTrace(); 67 | } catch (JSONException e) { 68 | e.printStackTrace(); 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | else if(action.equals("delete_record")) { 74 | try { 75 | deleteRecord(request, response); 76 | } catch (SQLException e) { 77 | e.printStackTrace(); 78 | } catch (JSONException e) { 79 | e.printStackTrace(); 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } 83 | } 84 | } 85 | 86 | public void showDebug(String msg){ 87 | System.out.println("["+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())+"]["+module+"/"+sub+"/ServletAction]"+msg); 88 | } 89 | 90 | public void getRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 91 | HttpSession session = request.getSession(); 92 | String existResultset= request.getParameter("exist_resultset"); 93 | if((existResultset==null) ||(existResultset.equals("null") || existResultset.isEmpty())) existResultset="0"; 94 | String userID=session.getAttribute("userID")==null?null:(String)session.getAttribute("userID"); 95 | UserFile query=new UserFile(); 96 | query.setDbName("FlightBooking"); 97 | query.setUserID(userID); 98 | JSONObject jsonObj=null; 99 | if(existResultset.equals("1")){ 100 | //要求提取之前查询结果,如果有就取出来,如果没有就重新查询一次,并且保存进session里 101 | if(session.getAttribute(module+"_"+sub+"_get_record_result")!=null){ 102 | jsonObj=(JSONObject)session.getAttribute(module+"_"+sub+"_get_record_result"); 103 | }else{ 104 | //如果没有就报错 105 | jsonObj=new JSONObject(); 106 | jsonObj.put("result_code",10); 107 | jsonObj.put("result_msg","exist_resultset参数不当,服务器当前没有结果数据!请重新设置!"); 108 | } 109 | }else{ 110 | //如果是新查询 111 | FileDao fileDao=new FileDao(); 112 | jsonObj=fileDao.getRecord(query); 113 | System.out.println(jsonObj); 114 | session.setAttribute(module+"_"+sub+"_get_record_result",jsonObj); 115 | } 116 | jsonObj.put("userID",userID); 117 | boolean isAjax=true; 118 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 119 | if(isAjax){ 120 | response.setContentType("application/json; charset=UTF-8"); 121 | PrintWriter out; 122 | try { 123 | out = response.getWriter(); 124 | out.print(jsonObj); 125 | out.flush(); 126 | out.close(); 127 | } catch (IOException e) { 128 | e.printStackTrace(); 129 | } 130 | }else{ 131 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 132 | int resultCode=0; 133 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 134 | showDebug(resultMsg); 135 | } 136 | } 137 | public void deleteRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 138 | String orderID = request.getParameter("orderID"); 139 | JSONObject jsonObj=null; 140 | if(orderID!=null){ 141 | FileDao fileDao=new FileDao(); 142 | jsonObj=fileDao.deleteRecord("FlightBooking",orderID); 143 | } 144 | boolean isAjax=true; 145 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 146 | if(isAjax){ 147 | response.setContentType("application/json; charset=UTF-8"); 148 | PrintWriter out; 149 | try { 150 | out = response.getWriter(); 151 | out.print(jsonObj); 152 | out.flush(); 153 | out.close(); 154 | } catch (IOException e){ 155 | e.printStackTrace(); 156 | } 157 | }else{ 158 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 159 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 160 | showDebug(resultMsg); 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /tickets_list.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | 4 | <% 5 | String id = request.getParameter("id"); 6 | String existResultset = request.getParameter("exist_resultset"); 7 | String userRole = (String)session.getAttribute("userRole"); 8 | %> 9 | 10 | 11 | 12 | 13 | 查询列表 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 |
48 | 49 | 52 | 53 | 82 |
83 |
84 |
85 |
86 | 87 | 88 | 89 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /src/flight/dao/FlightFile.java: -------------------------------------------------------------------------------- 1 | package flight.dao; 2 | 3 | //定义所有所需数据库数据的类 4 | public class FlightFile { 5 | //数据库字段 6 | private String flightID; 7 | private String srcDate; 8 | private String dstDate; 9 | private String price; 10 | private String srcTime; 11 | private String dstTime; 12 | private String company; 13 | private String srcPlace; 14 | private String dstPlace; 15 | private String srcAirport; 16 | private String dstAirport; 17 | 18 | 19 | 20 | private String valid; 21 | private String used; 22 | private String orderID; 23 | private String userID; 24 | private String userName; 25 | private String userRole; 26 | private String userPsd; 27 | private String userAge; 28 | private String userPlace; 29 | private String userCard; 30 | 31 | //传递条件查询用 32 | private String action; 33 | private String dbName; 34 | private String tableName=""; 35 | private String type=""; 36 | private String timeFrom=""; 37 | private String timeTo=""; 38 | private String timeSelect=""; 39 | private String groupId=""; 40 | private String groupSelect=""; 41 | private String timeInterval=""; 42 | private String userType=""; 43 | 44 | public FlightFile() { 45 | } 46 | 47 | public String getFlightID() { 48 | return flightID; 49 | } 50 | public void setFlightID(String flightID) { 51 | this.flightID = flightID; 52 | } 53 | 54 | public String getSrcDate() { 55 | return srcDate; 56 | } 57 | public void setSrcDate(String srcDate) { 58 | this.srcDate = srcDate; 59 | } 60 | 61 | public String getDstDate() { 62 | return dstDate; 63 | } 64 | public void setDstDate(String dstDate) { 65 | this.dstDate = dstDate; 66 | } 67 | 68 | public String getPrice() { 69 | return price; 70 | } 71 | public void setPrice(String price) { 72 | this.price = price; 73 | } 74 | 75 | public String getSrcTime() { 76 | return srcTime; 77 | } 78 | public void setSrcTime(String srcTime) { 79 | this.srcTime = srcTime; 80 | } 81 | 82 | public String getDstTime() { 83 | return dstTime; 84 | } 85 | public void setDstTime(String dstTime) { 86 | this.dstTime = dstTime; 87 | } 88 | 89 | public String getCompany() { 90 | return company; 91 | } 92 | public void setCompany(String company) { 93 | this.company = company; 94 | } 95 | 96 | public String getSrcPlace() { 97 | return srcPlace; 98 | } 99 | public void setSrcPlace(String srcPlace) { 100 | this.srcPlace = srcPlace; 101 | } 102 | 103 | public String getDstPlace() { 104 | return dstPlace; 105 | } 106 | public void setDstPlace(String dstPlace) { 107 | this.dstPlace = dstPlace; 108 | } 109 | 110 | public String getSrcAirport() { 111 | return srcAirport; 112 | } 113 | public void setSrcAirport(String srcAirport) { 114 | this.srcAirport = srcAirport; 115 | } 116 | 117 | public String getDstAirport() { 118 | return dstAirport; 119 | } 120 | public void setDstAirport(String dstAirport) { 121 | this.dstAirport = dstAirport; 122 | } 123 | 124 | public String getValid() { return valid; } 125 | public void setValid(String valid) { this.valid = valid; } 126 | 127 | public String getUsed() { return used; } 128 | public void setUsed(String used) { this.used = used; } 129 | 130 | public String getOrderID() { return orderID; } 131 | public void setOrderID(String orderID) { this.orderID = orderID; } 132 | 133 | public String getUserID() { 134 | return userID; 135 | } 136 | public void setUserID(String userID) { 137 | this.userID = userID; 138 | } 139 | 140 | public String getUserName() { 141 | return userName; 142 | } 143 | public void setUserName(String userName) { 144 | this.userName = userName; 145 | } 146 | 147 | public String getUserRole() { return userRole; } 148 | public void setUserRole(String userRole) { 149 | this.userRole = userRole; 150 | } 151 | 152 | public String getUserPsd() { return userPsd; } 153 | public void setUserPsd(String userPsd) { 154 | this.userPsd = userPsd; 155 | } 156 | 157 | public String getUserPlace() { 158 | return userPlace; 159 | } 160 | public void setUserPlace(String userAge) { 161 | this.userPlace = userPlace; 162 | } 163 | 164 | public String getUserAge() { 165 | return userAge; 166 | } 167 | public void setUserAge(String userAge) { 168 | this.userAge = userAge; 169 | } 170 | 171 | public String getUserCard() { 172 | return userCard; 173 | } 174 | public void setUserCard(String userCard) { 175 | this.userCard = userCard; 176 | } 177 | 178 | public String getDbName() { 179 | return dbName; 180 | } 181 | public void setDbName(String dbName) { this.dbName = dbName; } 182 | 183 | public String getAction() { 184 | return action; 185 | } 186 | public void setAction(String action) { this.action = action; } 187 | 188 | public String getTableName() { 189 | return tableName; 190 | } 191 | public void setTableName(String tableName) { 192 | this.tableName = tableName; 193 | } 194 | 195 | public String getType() { return type; } 196 | public void setType(String type) { 197 | this.type = type; 198 | } 199 | 200 | public String getTimeFrom() { 201 | return timeFrom; 202 | } 203 | public void setTimeFrom(String timeFrom) { 204 | this.timeFrom = timeFrom; 205 | } 206 | 207 | public String getTimeTo() { 208 | return timeTo; 209 | } 210 | public void setTimeTo(String timeTo) { 211 | this.timeTo = timeTo; 212 | } 213 | 214 | public String getTimeSelect() { 215 | return timeSelect; 216 | } 217 | public void setTimeSelect(String timeSelect) { 218 | this.timeSelect = timeSelect; 219 | } 220 | 221 | public String getGroupId() { 222 | return groupId; 223 | } 224 | public void setGroupId(String groupId) { 225 | this.groupId = groupId; 226 | } 227 | 228 | public String getGroupSelect() { 229 | return groupSelect; 230 | } 231 | public void setGroupSelect(String groupSelect) { 232 | this.groupSelect = groupSelect; 233 | } 234 | 235 | public String getTimeInterval() { 236 | return timeInterval; 237 | } 238 | public void setTimeInterval(String timeInterval) { 239 | this.timeInterval = timeInterval; 240 | } 241 | 242 | public String getUserType() { 243 | return userType; 244 | } 245 | public void setUserType(String userType) { 246 | this.userType = userType; 247 | } 248 | 249 | } 250 | -------------------------------------------------------------------------------- /modify-password.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 忘记密码 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 |
40 |
41 | 42 | 45 | 46 | 75 |
76 |
77 |
78 |
79 | 80 | 81 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /scripts/user_list.js: -------------------------------------------------------------------------------- 1 | var module="user"; 2 | var sub="file"; 3 | jQuery(document).ready(function() { 4 | Record.init(); 5 | Page.init(); 6 | }); 7 | var Record = function() { 8 | var initRecordStyle = function() { 9 | }; 10 | var initRecordList = function(){ 11 | getRecord(); 12 | } 13 | var getRecord = function(){ 14 | var orderID=$("#orderID").val(); 15 | var existResultset=$("#exist_resultset").val(); 16 | var url="user_file_servlet_action?action=get_record&orderID="+orderID+"&exist_resultset="+existResultset; 17 | $.ajax({ 18 | type:"get", 19 | url:url, 20 | dataType:'json', 21 | success:function (json) { 22 | Page.showResult(json); 23 | } 24 | }); 25 | }; 26 | 27 | var deleteRecord = function(orderID){ 28 | if(confirm("您确定要取消此订单吗?")){ 29 | if(orderID>-1){ 30 | $.post("user_file_servlet_action?action=delete_record&orderID="+orderID,function(json){ 31 | if(json.result_code == 1){ 32 | initRecordList(); 33 | } 34 | }) 35 | } 36 | } 37 | }; 38 | return { 39 | init: function() { 40 | initRecordList(); 41 | initRecordStyle(); 42 | }, 43 | deleteRecord:function(orderID){ 44 | deleteRecord(orderID); 45 | }, 46 | search:function(){ 47 | search(); 48 | } 49 | }; 50 | }(); 51 | 52 | Record.init(); 53 | 54 | var Page = function() { 55 | var html=""; 56 | var processError=function(json){ 57 | if(Frame!=null) 58 | Frame.processError(json); 59 | }; 60 | var showResult=function(json){ 61 | if(json!=null){ 62 | var list=json.aaData; 63 | var tip="当前查询到了 "+list.length+" 条订单"; 64 | //if($("#tip_div")) $("#tip_div").html(tip); 65 | if($("#record_list_tip")) $("#record_list_tip").html(tip); 66 | showRecordList(list); 67 | } 68 | }; 69 | var showRecordList=function(list){ 70 | for(var i=0;i"; 83 | html=html+"
"; 84 | html=html+"
"; 85 | html=html+"
"; 86 | html=html+"
订单号
"; 87 | html=html+"
"; 88 | html=html+"
"; 89 | html=html+"
"; 90 | html=html+"
"+orderID+"
"; 91 | html=html+"
"; 92 | html=html+"
"; 93 | html=html+"
"; 94 | html=html+"
"; 95 | html=html+"
"; 96 | html=html+"
订单信息
"; 97 | html=html+"
"; 98 | html=html+"
"; 99 | html=html+"
    "; 100 | html=html+"
  • 航班号:"+flightID+"
  • "; 101 | html=html+"
  • 出发日期:"+srcDate+"
  • "; 102 | html=html+"
  • 出发时间:"+srcTime+"
  • "; 103 | html=html+"
"; 104 | html=html+"
"; 105 | html=html+"
"; 106 | html=html+"
"; 107 | html=html+"
"; 108 | html=html+"
价格
"; 109 | html=html+"
"; 110 | html=html+"
"; 111 | html=html+" "+price+""; 112 | html=html+"
"; 113 | html=html+"
"; 114 | html=html+"
"; 115 | html=html+"
"; 116 | html=html+"
取消订单
"; 117 | html=html+"
"; 118 | html=html+"
"; 119 | if(valid==1){ 120 | html=html+" "; 123 | } 124 | else if(valid==0){ 125 | html=html+" "; 128 | } 129 | html=html+"
"; 130 | html=html+"
"; 131 | html=html+"
"; 132 | html=html+"
"; 133 | html=html+" "; 134 | }; 135 | var submitRecord=function(){ 136 | if(checkInput()==true){ 137 | page_form.action="../../"+module+"_"+sub+"_servlet_action"; 138 | page_form.submit(); 139 | } 140 | }; 141 | var checkInput=function(){ 142 | var bOk=true; 143 | var action=$("#action").val(); 144 | if(action==null || action==""){Frame.showMsg("名称不能为空!");bOk=false;}; 145 | return bOk; 146 | }; 147 | var deleteRecord=function(orderID){ 148 | Record.deleteRecord(orderID); 149 | }; 150 | var confirmBack=function(){ 151 | DraggableDialog.setId("confirm_back"); 152 | DraggableDialog.setdelete(Page.ondelete); 153 | DraggableDialog.setButtonTitle("确定","取消"); 154 | DraggableDialog.setOk(Page.returnBack); 155 | DraggableDialog.showMsg("确定要返回上一页吗?","提示"); 156 | }; 157 | var returnBack=function(){ 158 | history.go(-1); 159 | }; 160 | return { 161 | init: function() { 162 | initPageStyle(); 163 | handleButtonEvent(); 164 | }, 165 | processError:function(json){ 166 | processError(json); 167 | }, 168 | showResult:function(json){ 169 | showResult(json); 170 | }, 171 | showRecordList:function(list){ 172 | showRecordList(list); 173 | }, 174 | submitRecord:function(){ 175 | submitRecord(); 176 | }, 177 | deleteRecord:function(orderID){ 178 | deleteRecord(orderID); 179 | }, 180 | reload:function(){ 181 | window.location.reload(); 182 | }, 183 | confirmBack:function(){ 184 | confirmBack(); 185 | }, 186 | returnBack:function(){ 187 | returnBack(); 188 | }, 189 | } 190 | }(); -------------------------------------------------------------------------------- /forget-password.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 忘记密码 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 |
40 |
41 | 42 | 45 | 46 | 75 |
76 |
77 |
78 |
79 | 80 | 81 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /src/utility/FileUpload.java: -------------------------------------------------------------------------------- 1 | package utility; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | import java.text.SimpleDateFormat; 11 | import java.util.ArrayList; 12 | import java.util.Date; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | 16 | import javax.servlet.ServletException; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import javax.servlet.http.HttpSession; 20 | import org.apache.commons.fileupload.FileItemIterator; 21 | import org.apache.commons.fileupload.FileItemStream; 22 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; 23 | import org.apache.commons.fileupload.servlet.ServletFileUpload; 24 | import org.apache.commons.fileupload.util.Streams; 25 | import org.json.JSONException; 26 | import org.json.JSONObject; 27 | 28 | public class FileUpload { 29 | public HttpSession session = null; 30 | String databaseName = "XM06"; 31 | 32 | public void setSession(HttpSession session) throws Exception { 33 | try { 34 | this.session = session; 35 | if (session.getAttribute("unit_db_name") == null) { 36 | session.setAttribute("unit_db_name", databaseName); 37 | System.out.println("unit_db_name是空的,进行了缺省"); 38 | } else { 39 | } 40 | } catch (Exception e) { 41 | System.out.println("初始化Bean出现错误!" + e.getMessage()); 42 | } 43 | } 44 | 45 | private static final long serialVersionUID = 1L; 46 | File tmpDir = null; // 初始化上传文件的临时存放目录 47 | File fileDir = null; // 初始化上传文件后的保存目录 48 | String rootPath = null; // 初始化上传文件的根目录 49 | String filePath = null; // 初始化上传文件的保存目录 50 | String urlPath = null; // 初始化上传文件的访问URL 51 | 52 | public String getFilePath() { 53 | return filePath; 54 | } 55 | public void setFilePath(String filePath) { 56 | this.filePath = filePath; 57 | } 58 | public void showDebug(String msg) { 59 | System.out.println("[" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()) + "][utility/FileUpload]" + msg); 60 | } 61 | public String getRootPath() { 62 | return rootPath; 63 | } 64 | public void setRootPath(String rootPath) { 65 | this.rootPath = rootPath; 66 | } 67 | public String getUrlPath() { 68 | return urlPath; 69 | } 70 | public void setUrlPath(String urlPath) { 71 | this.urlPath = urlPath; 72 | } 73 | 74 | 75 | public JSONObject upload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException { 76 | initUploadDir(request, response); // 初始化目录 77 | String fileName = ""; 78 | JSONObject jsonObj = new JSONObject(); 79 | List jsonList = new ArrayList(); 80 | try { 81 | if (ServletFileUpload.isMultipartContent(request)) { 82 | DiskFileItemFactory dff = new DiskFileItemFactory();// 创建该对象 83 | dff.setRepository(tmpDir);// 指定上传文件的临时目录 84 | dff.setSizeThreshold(1024000);// 指定在内存中缓存数据大小,单位为byte 85 | ServletFileUpload sfu = new ServletFileUpload(dff);// 创建该对象 86 | sfu.setHeaderEncoding("UTF-8"); 87 | sfu.setSizeMax(20000000);// 指定单个上传文件的最大尺寸 88 | sfu.setSizeMax(100000000);// 指定一次上传多个文件的总尺寸 89 | FileItemIterator fii = sfu.getItemIterator(request);// 解析request 90 | // 请求,并返回FileItemIterator集合 91 | while (fii.hasNext()) { 92 | FileItemStream fis = fii.next();// 从集合中获得一个文件流 93 | int fileSize = 0; 94 | if (!fis.isFormField() && fis.getName().length() > 0) {// 过滤掉表单中非文件域 95 | if (fis.getName().lastIndexOf("//") > 0) { 96 | fileName = fis.getName().substring(fis.getName().lastIndexOf("//"));// 获得上传文件的文件名 97 | } else { 98 | fileName = fis.getName();// 获得上传文件的文件名 99 | } 100 | BufferedInputStream in = new BufferedInputStream(fis.openStream());// 获得文件输入流 101 | BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(fileDir + "\\" + fileName)));// 获得文件输出流 102 | fileSize = (int) Streams.copy(in, out, true);// 开始把文件写到你指定的上传文件夹 103 | } 104 | // 构造返回结果的json 105 | HashMap map = new HashMap(); 106 | map.put("file_name", fileName); 107 | map.put("file_path", filePath); 108 | map.put("file_size", fileSize); 109 | map.put("url_path", urlPath); 110 | //showDebug("fileName="+fileName+",filePath="+filePath+",fileSize="+fileSize+",urlPath="+urlPath); 111 | jsonList.add(map); 112 | } 113 | // 返回json的结果 114 | } 115 | } catch (Exception e) { 116 | e.printStackTrace(); 117 | } 118 | jsonObj.put("files", jsonList); 119 | jsonObj.put("version", "1.0"); 120 | String json = jsonObj.toString(); 121 | return jsonObj; 122 | } 123 | 124 | /* 125 | * 对上传文件夹和临时文件夹进行初始化 找到根目录,创建该目录下的临时路径和用户路径 用户上传的文件放在对应的用户路径下 前面应该定义几个公共变量 126 | * File tmpDir = null; // 初始化上传文件的临时存放目录 File fileDir = null; // 127 | * 初始化上传文件后的保存目录 String rootPath=null; // 初始化上传文件的根目录 128 | */ 129 | public void initUploadDir(HttpServletRequest request, HttpServletResponse response) { 130 | HttpSession session = request.getSession(); 131 | String userId = null; 132 | if (session.getAttribute("user_id") == null) { 133 | userId = "public"; 134 | } else { 135 | userId = (String) session.getAttribute("user_id"); 136 | } 137 | if (rootPath == null || rootPath.isEmpty()) 138 | rootPath = "C:\\"; 139 | String tmpPath = rootPath + "temp\\"; // 临时路径 140 | if ((filePath == null) || filePath.isEmpty()) { 141 | filePath = rootPath + "upload\\" + userId + "\\"; // 用户路径 142 | urlPath = "/upload/" + userId + "/"; // 用户路径 143 | } 144 | tmpDir = new File(tmpPath); 145 | fileDir = new File(filePath); 146 | if (!tmpDir.exists() && !tmpDir.isDirectory()) 147 | tmpDir.mkdirs(); 148 | if (!fileDir.exists() && !fileDir.isDirectory()) 149 | fileDir.mkdirs(); 150 | } 151 | 152 | /** 153 | * 支持中文,文件名长度无限制 不支持国际化 154 | */ 155 | public void download(HttpServletRequest request, HttpServletResponse response,String filePath,String fileName) throws Exception { 156 | response.setContentType("text/html;charset=utf-8"); 157 | request.setCharacterEncoding("UTF-8"); 158 | java.io.BufferedInputStream bis = null; 159 | java.io.BufferedOutputStream bos = null; 160 | String filePathName=filePath+fileName; 161 | try { 162 | long fileLength = new File(filePathName).length(); 163 | 164 | response.setContentType("application/x-msdownload;"); 165 | response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("GB2312"), "ISO8859-1")); 166 | response.setHeader("Content-Length", String.valueOf(fileLength)); 167 | 168 | bis = new BufferedInputStream(new FileInputStream(filePathName)); 169 | bos = new BufferedOutputStream(response.getOutputStream()); 170 | byte[] buff = new byte[2048]; 171 | int bytesRead; 172 | while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { 173 | bos.write(buff, 0, bytesRead); 174 | } 175 | } catch (Exception e) { 176 | e.printStackTrace(); 177 | } finally { 178 | if (bis != null) 179 | bis.close(); 180 | if (bos != null) 181 | bos.close(); 182 | } 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/flight/dao/FileDao.java: -------------------------------------------------------------------------------- 1 | package flight.dao; 2 | 3 | import java.io.IOException; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | import dao.FB_db; 11 | 12 | //从数据库取所需数据存入列表,返回jsonList 13 | public class FileDao { 14 | //返回结果集 15 | public JSONObject getRecord(FlightFile query) throws SQLException, IOException, JSONException { 16 | String tableName1="ticket_info"; 17 | String tableName2="seat_info"; 18 | String tableName3="flight_info"; 19 | //开始查询数据库 20 | String resultMsg="OK"; 21 | int resultCode=0; 22 | List jsonList = new ArrayList(); 23 | try { 24 | FB_db query_db = new FB_db(query.getDbName()); //建立与数据库交互变量 25 | String sql="SELECT * FROM ticket_info JOIN flight_info " + 26 | "ON ticket_info.flightID = flight_info.flightID" + 27 | " WHERE " + 28 | "srcPlace = " + "'" + query.getSrcPlace() + "'" + " AND " + 29 | "dstPlace = " + "'" + query.getDstPlace() + "'" + 30 | " AND ticket_info.srcDate = " + "'" + query.getSrcDate() + "'"; 31 | int count=0; 32 | ResultSet rs = query_db.executeQuery(sql); //由自定义的sql语句执行数据库查询操作 33 | while (rs.next()) { 34 | List list = new ArrayList(); //创建列表对象存入数据库表数据 35 | list.add(rs.getString("flightID")); 36 | list.add(rs.getString("srcDate")); 37 | list.add(rs.getString("dstDate")); 38 | list.add(rs.getString("price")); 39 | list.add(rs.getString("srcTime")); 40 | list.add(rs.getString("dstTime")); 41 | list.add(rs.getString("company")); 42 | list.add(rs.getString("srcPlace")); 43 | list.add(rs.getString("dstPlace")); 44 | list.add(rs.getString("srcAirport")); 45 | list.add(rs.getString("dstAirport")); 46 | //list.add(rs.getString("isFull")); 47 | //list.add(rs.getString("passengerNum")); 48 | //list.add(rs.getString("seatNum")); 49 | //权限设置 50 | /* 51 | if(query.getUserID() != null && query.getUserID().equals(rs.getString("userID"))){ 52 | list.add("1"); 53 | }else{ 54 | list.add("0"); 55 | } 56 | */ 57 | list.add(count); 58 | count=count+1; //做上下记录导航用 59 | System.out.println(list); 60 | jsonList.add(list); //传入jsonList 61 | } 62 | rs.close(); 63 | query_db.close(); 64 | } catch (SQLException sqlexception) { 65 | sqlexception.printStackTrace(); 66 | resultCode=10; 67 | resultMsg="查询数据库出现错误!"+sqlexception.getMessage(); 68 | } 69 | //数据库查询完毕,得到了json数组jsonList 70 | //jsonList.clear(); 71 | //下面开始构建返回的json 72 | JSONObject jsonObj=new JSONObject(); 73 | jsonObj.put("aaData",jsonList); 74 | jsonObj.put("result_msg",resultMsg);//如果发生错误就设置成"error"等 75 | jsonObj.put("result_code",resultCode);//返回0表示正常,不等于0就表示有错误产生,错误代码 76 | //System.out.println(jsonObj); 77 | return jsonObj; 78 | } 79 | 80 | public JSONObject deleteRecord(String flightID,String srcDate,String srcTime) throws JSONException, SQLException{ 81 | String tableName="ticket_info"; 82 | FB_db query_db = new FB_db("FlightBooking"); 83 | String sql="delete from "+tableName+" where flightID="+flightID+" and srcDate=" + srcDate + " and srcTime=" + srcTime; 84 | int result = query_db.executeUpdate(sql); 85 | System.out.println(sql); 86 | query_db.close(); 87 | //下面开始构建返回的json 88 | JSONObject jsonObj=new JSONObject(); 89 | jsonObj.put("result_msg","OK");//如果发生错误就设置成"error"等 90 | jsonObj.put("result_code",result);//返回0表示正常,不等于0就表示有错误产生,错误代码 91 | return jsonObj; 92 | } 93 | 94 | public JSONObject modifyRecord(FlightFile flightFile,String flightID,String srcDate,String SrcTime) throws JSONException, SQLException{ 95 | FB_db query_db = new FB_db("FlightBooking"); 96 | String sql1="UPDATE ticket_info SET flightID='"+flightFile.getFlightID()+"', srcDate='"+flightFile.getSrcDate() + 97 | "', dstDate='" + flightFile.getDstDate() + "', price='" + flightFile.getPrice() + 98 | "', srcTime='" + flightFile.getSrcTime() + "', dstTime='" + flightFile.getDstTime() + 99 | "' where flightID='" + flightID + "'"; 100 | int result1 = query_db.executeUpdate(sql1); 101 | System.out.println(sql1); 102 | String sql2="UPDATE flight_info SET company="+flightFile.getCompany()+"', flightID='"+flightFile.getFlightID() + 103 | "', srcPlace='" + flightFile.getSrcPlace() + "', dstPlace='" + flightFile.getDstPlace() + 104 | "', srcAirport='" + flightFile.getSrcAirport() + "', dstAirport='" + flightFile.getDstAirport() + 105 | "' where flightID='" + flightID + "' and srcDate='" + srcDate + "' and srcTime='" + SrcTime + "'"; 106 | int result2 = query_db.executeUpdate(sql2); 107 | System.out.println(sql2); 108 | query_db.close(); 109 | 110 | //下面开始构建返回的json 111 | JSONObject jsonObj=new JSONObject(); 112 | jsonObj.put("result_msg","OK");//如果发生错误就设置成"error"等 113 | jsonObj.put("result_code",result1);//返回0表示正常,不等于0就表示有错误产生,错误代码 114 | jsonObj.put("result_code",result2); 115 | return jsonObj; 116 | } 117 | 118 | public JSONObject addRecord(FlightFile flightFile) throws JSONException, SQLException{ 119 | FB_db query_db = new FB_db("FlightBooking"); 120 | String sql1="INSERT INTO ticket_info(flightID,srcDate,dstDate,price,srcTime,dstTime) "+ "values('"+flightFile.getFlightID()+"','"+flightFile.getSrcDate() + 121 | "','"+ flightFile.getDstDate() +"','"+ flightFile.getPrice() +"','"+ flightFile.getSrcTime() +"','"+ flightFile.getDstTime()+"')"; 122 | int result1 = query_db.executeUpdate(sql1); 123 | System.out.println(sql1); 124 | String sql2="INSERT INTO flight_info(company,flightID,srcPlace,dstPlace,srcAirport,dstAirport) "+ "values('"+flightFile.getCompany()+"','"+flightFile.getFlightID() + 125 | "','"+ flightFile.getSrcPlace() +"','"+ flightFile.getDstPlace() +"','"+ flightFile.getSrcAirport() +"','"+ flightFile.getDstAirport()+"')"; 126 | int result2 = query_db.executeUpdate(sql2); 127 | System.out.println(sql2); 128 | query_db.close(); 129 | 130 | //下面开始构建返回的json 131 | JSONObject jsonObj=new JSONObject(); 132 | jsonObj.put("result_msg","OK");//如果发生错误就设置成"error"等 133 | jsonObj.put("result_code",result1);//返回0表示正常,不等于0就表示有错误产生,错误代码 134 | jsonObj.put("result_code",result2);//返回0表示正常,不等于0就表示有错误产生,错误代码 135 | return jsonObj; 136 | } 137 | 138 | private String createGetRecordSql(FlightFile query) { 139 | String sql = ""; 140 | String where = ""; 141 | sql="select * from "+query.getTableName(); 142 | return sql; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/common/LoginServlet.java: -------------------------------------------------------------------------------- 1 | package common; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | import java.io.IOException; 7 | import java.io.PrintWriter; 8 | import java.sql.Connection; 9 | import java.sql.DriverManager; 10 | import java.sql.ResultSet; 11 | import java.sql.Statement; 12 | 13 | import javax.servlet.ServletException; 14 | import javax.servlet.http.HttpServlet; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import javax.servlet.http.HttpSession; 18 | 19 | public class LoginServlet extends HttpServlet { 20 | 21 | private static final long serialVersionUID = 1L; 22 | String userID; 23 | String userPsd; 24 | String userName; 25 | String userAge; 26 | String userPlace; 27 | String userRole; 28 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 29 | try { 30 | System.out.println("请求"); 31 | request.setCharacterEncoding("utf-8"); 32 | String src = "sign-in"; 33 | //String src = request.getParameter("source"); 34 | System.out.println(src); 35 | if(src.equals("sign-in")){//如果是用于登陆的请求 36 | doPost(request,response); 37 | System.out.println("登陆请求"); 38 | } 39 | else if(src.equals("user-info")){//如果是用户信息修改的请求 40 | modify_info(request,response); 41 | System.out.println("修改用户信息请求"); 42 | } 43 | //doPost(request,response); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | // 该方法用户验证用户名和密码 49 | public int check(String userid, String userpass) { 50 | String URL = "jdbc:mysql://localhost:3306/FLightBooking"; 51 | String NAME = "root"; 52 | String PASS = "woaizhoujielun"; 53 | String SQL = "select userPsd from user_info where userID='"+ userid + "'"; 54 | 55 | try { 56 | // 加载驱动 57 | Class.forName("com.mysql.jdbc.Driver"); 58 | // 连接对象 59 | Connection con = DriverManager.getConnection(URL, NAME, PASS); 60 | // 语句对象 61 | Statement stmt = con.createStatement(); 62 | ResultSet rs = stmt.executeQuery(SQL); 63 | 64 | // 得到该用户名的密码 65 | String tmpPass = ""; 66 | if (rs.next()) { 67 | tmpPass = rs.getString("userPsd"); 68 | } 69 | 70 | // 关闭对象,释放资源 71 | rs.close(); 72 | stmt.close(); 73 | con.close(); 74 | 75 | // 判断密码是否正确 76 | if (tmpPass.equals(userpass)) { 77 | return 1; 78 | } 79 | 80 | } catch (Exception e) { 81 | // TODO Auto-generated catch block 82 | e.printStackTrace(); 83 | } 84 | return 0; 85 | 86 | } 87 | 88 | public int saveInfo(String userID, HttpSession session) { 89 | String URL = "jdbc:mysql://localhost:3306/FLightBooking"; 90 | String NAME = "root"; 91 | String PASS = "woaizhoujielun"; 92 | String sql="select userName,userAge,userPlace,userRole from user_info where userID='"+ userID + "'"; 93 | 94 | try { 95 | // 加载驱动 96 | Class.forName("com.mysql.jdbc.Driver"); 97 | // 连接对象 98 | Connection con = DriverManager.getConnection(URL, NAME, PASS); 99 | // 语句对象 100 | Statement stmt = con.createStatement(); 101 | //获取显示数据 102 | ResultSet rs = stmt.executeQuery(sql); 103 | // 得到该用户的信息存入session 104 | if (rs.next()) { 105 | userName = rs.getString("userName"); 106 | userAge = rs.getString("userAge"); 107 | userPlace = rs.getString("userPlace"); 108 | userRole = rs.getString("userRole"); 109 | session.setAttribute("userName", userName); 110 | session.setAttribute("userAge", userAge); 111 | session.setAttribute("userPlace", userPlace); 112 | session.setAttribute("userRole", userRole); 113 | } 114 | rs.close(); 115 | // 关闭对象,释放资源 116 | stmt.close(); 117 | con.close(); 118 | } catch (Exception e) { 119 | // TODO Auto-generated catch block 120 | e.printStackTrace(); 121 | } 122 | return 0; 123 | 124 | } 125 | 126 | public void modify_info(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { 127 | HttpSession session = request.getSession(); 128 | String URL = "jdbc:mysql://localhost:3306/FLightBooking"; 129 | String NAME = "root"; 130 | String PASS = "woaizhoujielun"; 131 | String userID_new = request.getParameter("userID");//新手机号 132 | userName = request.getParameter("userName"); 133 | userAge = request.getParameter("userAge"); 134 | userPlace = request.getParameter("userPlace"); 135 | String sql="UPDATE user_info SET userName='"+userName+"',userAge='"+userAge+"',userPlace='"+userPlace+ 136 | "',userID='" +userID_new+ "' WHERE userID='"+userID+"'"; 137 | try { 138 | // 加载驱动 139 | Class.forName("com.mysql.jdbc.Driver"); 140 | // 连接对象 141 | Connection con = DriverManager.getConnection(URL, NAME, PASS); 142 | // 语句对象 143 | Statement stmt = con.createStatement(); 144 | //获取显示数据 145 | int rs = stmt.executeUpdate(sql); 146 | userID = userID_new; 147 | // 得到该用户的信息存入session 148 | if(rs!=0){ 149 | session.setAttribute("userID", userID); 150 | session.setAttribute("userName", userName); 151 | session.setAttribute("userAge", userAge); 152 | session.setAttribute("userPlace", userPlace); 153 | } 154 | // 关闭对象,释放资源 155 | stmt.close(); 156 | con.close(); 157 | } catch (Exception e) { 158 | // TODO Auto-generated catch block 159 | e.printStackTrace(); 160 | } 161 | } 162 | @Override 163 | protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { 164 | // TODO Auto-generated method stub 165 | // 获取用户的用户名和口令 166 | request.setCharacterEncoding("utf-8"); 167 | userID = request.getParameter("userID"); 168 | userPsd = request.getParameter("userPsd"); 169 | String source = request.getParameter("source"); 170 | System.out.println(source); 171 | System.out.println("[LoginServlet-doGet]userid=" + userID+ " userpass=" + userPsd); 172 | int result = check(userID, userPsd); 173 | 174 | // 如果登录成功,就把用户名写入session中,并且转向success.jsp, 175 | // 否则转向failure.jsp 176 | System.out.println("[LoginServlet-doGet]result=" + result); 177 | if (result == 1) { 178 | HttpSession session = request.getSession(); 179 | session.setAttribute("userID", userID);//账号名 180 | session.setAttribute("login_status",1);//是否登陆 181 | saveInfo(userID,session);//将其他信息保存到SESSION 182 | //response.sendRedirect("index.jsp"); 183 | } 184 | HttpSession session = request.getSession(); 185 | int login_status = (int)session.getAttribute("login_status"); 186 | try { 187 | JSONObject jsonObj=new JSONObject(); 188 | try { 189 | jsonObj.put("flag",result); 190 | jsonObj.put("login_status",login_status); 191 | } catch (JSONException e) { 192 | e.printStackTrace(); 193 | } 194 | response.setContentType("application/json; charset=UTF-8"); 195 | PrintWriter out; 196 | out = response.getWriter(); 197 | out.print(jsonObj); 198 | System.out.println(jsonObj.toString()); 199 | out.flush(); 200 | out.close(); 201 | } catch (IOException e) { 202 | e.printStackTrace(); 203 | } 204 | } 205 | 206 | protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { 207 | // TODO Auto-generated method stub 208 | doGet(request, response); 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /signup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 用户注册 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 35 | 36 | 42 |
43 |
44 |
45 |
46 | 47 | 48 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /homepage.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | 4 | <% 5 | String id = request.getParameter("id"); 6 | String existResultset = request.getParameter("exist_resultset"); 7 | %> 8 | 9 | 10 | 11 | 12 | Home 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 |
46 |
47 | 48 | 51 | 52 | 81 |
82 |
83 |
84 |
85 | 86 | 87 | 88 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 229 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /user-info.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | <%@ page import="java.sql.Connection" %> 4 | <%@ page import="java.sql.DriverManager" %> 5 | <%@ page import="java.sql.Statement" %> 6 | <%@ page import="java.sql.ResultSet" %> 7 | <% 8 | session = request.getSession(); 9 | String existResultset= request.getParameter("exist_resultset"); 10 | if((existResultset==null) ||(existResultset.equals("null") || existResultset.isEmpty())) existResultset="0"; 11 | String userID=session.getAttribute("userID")==null?null:(String)session.getAttribute("userID"); 12 | String userName = session.getAttribute("userName")==null?null:(String)session.getAttribute("userName"); 13 | String userAge =session.getAttribute("userAge")==null?null:(String)session.getAttribute("userAge"); 14 | String userPlace = session.getAttribute("userPlace")==null?null:(String)session.getAttribute("userPlace"); 15 | %> 16 | 17 | 18 | 19 | 个人中心 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 |
55 | 56 | 59 | 60 | 88 |
89 |
90 |
91 |
92 | 93 | 94 | 132 | 133 | 134 | 135 | 136 | 137 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /ticket_add_div.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | 4 | 5 | 6 | 管理员添加页面 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 37 | 38 | 67 |
68 |
69 |
70 |
71 | 72 | 73 | 86 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /ticket_modify_div.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8"%> 2 | <%@page import="java.text.*"%> 3 | 4 | 5 | 6 | 管理员修改页面 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 |
33 | 34 | 37 | 38 | 67 |
68 |
69 |
70 |
71 | 72 | 73 | 86 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /scripts/ticket_list.js: -------------------------------------------------------------------------------- 1 | var module="flight"; 2 | var sub="file"; 3 | 4 | jQuery(document).ready(function(){ 5 | Record.init(); 6 | Page.init(); 7 | }); 8 | 9 | var Record = function() { 10 | var userId=undefined; 11 | var userName=undefined; 12 | var userRole=undefined; 13 | var initRecordList = function(){ 14 | getRecord(); 15 | }; 16 | var getRecord = function(){ 17 | var srcPlace = localStorage["srcPlace"]; 18 | var dstPlace = localStorage["dstPlace"]; 19 | var srcDate = localStorage["srcDate"]; 20 | var url="flight_file_servlet_action?action=get_record&srcPlace="+srcPlace+"&dstPlace="+dstPlace+"&srcDate="+srcDate; 21 | $.ajax({ 22 | type:"get", 23 | url:url, 24 | dataType:'json', 25 | success:function (json) { 26 | Page.showResult(json); 27 | } 28 | }); 29 | }; 30 | 31 | var deleteRecord = function(flightID,srcDate,srcTime){ 32 | if(confirm("您确定要删除此记录吗?")){ 33 | var url="flight_file_servlet_action?action=delete_record&flightID="+flightID+"&srcDate="+srcDate+"&srcTime="+srcTime; 34 | $.ajax({ 35 | type:"post", 36 | url:url, 37 | dataType:'json', 38 | success:function (json) { 39 | if(json.result_code == 1){ 40 | alert("删除成功!"); 41 | } 42 | } 43 | }); 44 | } 45 | }; 46 | 47 | return { 48 | init: function() { 49 | initRecordList(); 50 | }, 51 | deleteRecord:function(id){ 52 | deleteRecord(id); 53 | }, 54 | search:function(){ 55 | search(); 56 | } 57 | }; 58 | }(); 59 | 60 | var Page = function() { 61 | var html=""; 62 | var processError=function(json){ 63 | if(Frame!=null) 64 | Frame.processError(json); 65 | }; 66 | var showResult=function(json){ 67 | if(json!=null){ 68 | var list=json.aaData; 69 | var tip="当前查询到了 "+list.length+" 条订单"; 70 | //if($("#tip_div")) $("#tip_div").html(tip); 71 | if($("#record_list_tip")) 72 | $("#record_list_tip").html(tip); 73 | showRecordList(list); 74 | var userRole=$("#userRole").val(); 75 | if(userRole=="admin"){ 76 | var html_add=""; 77 | html_add=html_add+"
"; 78 | html_add=html_add+"
"; 79 | html_add=html_add+"
"; 80 | html_add=html_add+"
"; 81 | html_add=html_add+"
"; 82 | $("#add").html(html_add); 83 | } 84 | } 85 | }; 86 | var showRecordList=function(list){ 87 | for(var i=0;i"; 105 | html=html+"
"; 106 | html=html+"
"; 107 | html=html+"
"; 108 | html=html+"
航班信息
"; 109 | html=html+"
"; 110 | html=html+"
"; 111 | html=html+" \"\""; 112 | html=html+"
"; 113 | html=html+"
" + company + "
"; 114 | html=html+"

" + flightID + "

"; 115 | html=html+"
"; 116 | html=html+"
"; 117 | html=html+"
"; 118 | html=html+"
"; 119 | html=html+"
"; 120 | html=html+"
出发/到达时间
"; 121 | html=html+"
"; 122 | html=html+"
"; 123 | html=html+"
" + srcAirport + "
"; 124 | html=html+"
" + srcDate + "
"; 125 | html=html+"
" + srcTime + "
"; 126 | html=html+"
"; 127 | html=html+"
" + dstAirport + "
"; 128 | html=html+"
" + dstDate + "
"; 129 | html=html+"
" + dstTime + "
"; 130 | html=html+"
"; 131 | html=html+"
"; 132 | html=html+"
" 133 | html=html+"
"; 134 | html=html+"
价格
"; 135 | html=html+"
"; 136 | html=html+"
"; 137 | html=html+"

Price is now:

"; 138 | html=html+" " + price + ""; 139 | html=html+"
"; 140 | html=html+"
"; 141 | html=html+"
"; 142 | html=html+"
"; 143 | html=html+"
预订
"; 144 | html=html+"
"; 145 | html=html+"
"; 146 | if(userRole=="normal"){ 147 | html=html+" "; 148 | } 149 | if(userRole=="admin"){ 150 | html=html+" "; 151 | html=html+" "; 152 | } 153 | html=html+"
"; 154 | html=html+"
"; 155 | html=html+"
"; 156 | html=html+"
"; 157 | html=html+" "; 158 | 159 | }; 160 | 161 | var modifyRecord=function(json){ 162 | localStorage.flightID = flightID; 163 | localStorage.srcDate = srcDate; 164 | localStorage.dstDate = dstDate; 165 | localStorage.price = price; 166 | localStorage.srcTime = srcTime; 167 | localStorage.dstTime = dstTime; 168 | localStorage.srcAirport = srcAirport; 169 | localStorage.dstAirport = dstAirport; 170 | localStorage.company = company; 171 | localStorage.srcPlace = json[7]; 172 | localStorage.dstPlace = json[8]; 173 | window.open("ticket_modify_div.jsp"); 174 | } 175 | 176 | var submitRecord=function(){ 177 | if(checkInput()==true){ 178 | page_form.action="flight_file_servlet_action"; 179 | page_form.submit(); 180 | } 181 | }; 182 | function reserveRecord(flightID,srcDate,srcTime){ 183 | var orderID=""; 184 | for(var i=0;i<10;i++){ 185 | orderID+=(parseInt)(Math.random()*10); 186 | } 187 | var valid=1; 188 | var used=0; 189 | $.ajax({ 190 | type: "POST", 191 | url: 'order_file_servlet_action', 192 | dataType: "json", 193 | data:{orderID:orderID,flightID:flightID,srcDate:srcDate,srcTime:srcTime,valid:valid,used:used}, 194 | success: function (json) { 195 | if (json.flag == 1) { 196 | alert("预定成功!"); 197 | } 198 | else{ 199 | alert("请先登录!"); 200 | } 201 | }, 202 | error: function (message) { 203 | alert("error"); 204 | } 205 | }); 206 | }; 207 | 208 | var checkInput=function(){ 209 | var bOk=true; 210 | var action=$("#action").val(); 211 | if(action==null || action==""){Frame.showMsg("名称不能为空!");bOk=false;}; 212 | return bOk; 213 | }; 214 | var deleteRecord=function(flightID,srcDate,srcTime){ 215 | Record.deleteRecord(flightID,srcDate,srcTime); 216 | }; 217 | var confirmBack=function(){ 218 | DraggableDialog.setId("confirm_back"); 219 | DraggableDialog.setdelete(Page.ondelete); 220 | DraggableDialog.setButtonTitle("确定","取消"); 221 | DraggableDialog.setOk(Page.returnBack); 222 | DraggableDialog.showMsg("确定要返回上一页吗?","提示"); 223 | }; 224 | var ondelete=function(){ 225 | DraggableDialog.close(); 226 | } 227 | var returnBack=function(){ 228 | history.go(-1); 229 | }; 230 | return { 231 | init: function() { 232 | initPageStyle(); 233 | handleButtonEvent(); 234 | }, 235 | processError:function(json){ 236 | processError(json); 237 | }, 238 | showResult:function(json){ 239 | showResult(json); 240 | }, 241 | showRecordList:function(list){ 242 | showRecordList(list); 243 | }, 244 | submitRecord:function(){ 245 | submitRecord(); 246 | }, 247 | deleteRecord:function(flightID,srcDate,srcTime){ 248 | deleteRecord(flightID,srcDate,srcTime); 249 | }, 250 | modifyRecord:function(json){ 251 | modifyRecord(json); 252 | }, 253 | reload:function(){ 254 | window.location.reload(); 255 | }, 256 | confirmBack:function(){ 257 | confirmBack(); 258 | }, 259 | reserveRecord:function(flightID,srcDate,srcTime){ 260 | reserveRecord(flightID,srcDate,srcTime); 261 | }, 262 | returnBack:function(){ 263 | returnBack(); 264 | } 265 | } 266 | }(); -------------------------------------------------------------------------------- /src/flight/file/ServletAction.java: -------------------------------------------------------------------------------- 1 | package flight.file; 2 | 3 | import dao.FB_db; 4 | import dao.FB_id; 5 | 6 | import java.io.*; 7 | import java.io.IOException; 8 | import java.io.PrintWriter; 9 | import java.io.UnsupportedEncodingException; 10 | import java.sql.ResultSet; 11 | import java.sql.SQLException; 12 | import java.text.SimpleDateFormat; 13 | import java.util.ArrayList; 14 | import java.util.Date; 15 | import java.util.Iterator; 16 | import java.util.List; 17 | 18 | import javax.servlet.ServletException; 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | import javax.servlet.http.HttpSession; 23 | 24 | import org.jfree.chart.ChartFactory; 25 | import org.jfree.chart.JFreeChart; 26 | import org.jfree.chart.plot.PlotOrientation; 27 | import org.jfree.chart.servlet.ServletUtilities; 28 | import org.jfree.data.DefaultCategoryDataset; 29 | import org.jfree.data.DefaultPieDataset; 30 | import org.json.JSONArray; 31 | import org.json.JSONException; 32 | import org.json.JSONObject; 33 | 34 | import flight.dao.FlightFile; 35 | import flight.dao.FileDao; 36 | 37 | import utility.LogEvent; 38 | import utility.MD5Util; 39 | 40 | //根据前端发来的action指令采取对应措施 41 | //将数据库取出的数据jsonList传到前端 42 | public class ServletAction extends HttpServlet { 43 | public String module = "flight"; 44 | public String sub = "file"; 45 | 46 | public SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 47 | public LogEvent flightLog = new LogEvent(); 48 | 49 | public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 50 | try { 51 | processAction(request,response); 52 | } catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | 57 | public void processAction(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 58 | request.setCharacterEncoding("UTF-8"); 59 | String action = request.getParameter("action"); 60 | showDebug("processAction收到的action是:"+action); 61 | if (action.equals("get_record")){ 62 | try { 63 | getRecord(request, response); 64 | } catch (SQLException e) { 65 | e.printStackTrace(); 66 | } catch (JSONException e) { 67 | e.printStackTrace(); 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | else if(action.equals("delete_record")) { 73 | try { 74 | deleteRecord(request, response); 75 | } catch (SQLException e) { 76 | e.printStackTrace(); 77 | } catch (JSONException e) { 78 | e.printStackTrace(); 79 | } catch (Exception e) { 80 | e.printStackTrace(); 81 | } 82 | } 83 | else if(action.equals("modify_record")) { 84 | try { 85 | modifyRecord(request, response); 86 | } catch (SQLException e) { 87 | e.printStackTrace(); 88 | } catch (JSONException e) { 89 | e.printStackTrace(); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | } 94 | else if(action.equals("add_record")) { 95 | try { 96 | addRecord(request, response); 97 | } catch (SQLException e) { 98 | e.printStackTrace(); 99 | } catch (JSONException e) { 100 | e.printStackTrace(); 101 | } catch (Exception e) { 102 | e.printStackTrace(); 103 | } 104 | } 105 | } 106 | 107 | public void processError(HttpServletRequest request, HttpServletResponse response,int errorNo,String errorMsg) throws JSONException, IOException{ 108 | String action = request.getParameter("action"); 109 | //errorNo=0->没有错误 110 | //errorNo=1->action是空值 111 | //errorNo=2->没有对应的处理该action的函数 112 | //errorNo=3->session超时 113 | showDebug("错误信息:"+errorMsg+",代码:"+errorNo); 114 | JSONObject jsonObj=new JSONObject(); 115 | boolean isAjax=true; 116 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 117 | if(isAjax){ 118 | jsonObj.put("result_code",errorNo); 119 | jsonObj.put("result_msg",errorMsg); 120 | jsonObj.put("action",action); 121 | response.setContentType("application/json; charset=UTF-8"); 122 | PrintWriter out; 123 | try { 124 | out = response.getWriter(); 125 | out.print(jsonObj); 126 | out.flush(); 127 | out.close(); 128 | } catch (IOException e) { 129 | e.printStackTrace(); 130 | } 131 | }else{ 132 | errorMsg = java.net.URLEncoder.encode(errorMsg, "UTF-8"); 133 | String url = errorMsg; 134 | showDebug(url); 135 | response.sendRedirect(url); 136 | } 137 | } 138 | 139 | public void showDebug(String msg){ 140 | System.out.println("["+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())+"]["+module+"/ServletAction]"+msg); 141 | } 142 | 143 | //从前端获取数据存入变量中,用以调用数据库其他数据 144 | public void getRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 145 | HttpSession session = request.getSession(); 146 | String existResultset= request.getParameter("exist_resultset"); 147 | if((existResultset==null) ||(existResultset.equals("null") || existResultset.isEmpty())) existResultset="0"; 148 | //获取userID和username 149 | String userId=session.getAttribute("userID")==null?null:(String)session.getAttribute("userID"); 150 | String srcPlace=request.getParameter("srcPlace"); 151 | String dstPlace=request.getParameter("dstPlace"); 152 | String srcDate=request.getParameter("srcDate"); 153 | System.out.println(srcPlace); 154 | System.out.println(dstPlace); 155 | System.out.println(srcDate); 156 | //数据获取完毕,开始和数据库交互 157 | FlightFile query=new FlightFile(); 158 | query.setDbName("FlightBooking"); 159 | query.setUserID(userId); 160 | query.setSrcPlace(srcPlace); 161 | query.setDstPlace(dstPlace); 162 | query.setSrcDate(srcDate); 163 | JSONObject jsonObj=null; 164 | if(existResultset.equals("1")){ 165 | //要求提取之前查询结果,如果有就取出来,如果没有就重新查询一次,并且保存进session里 166 | if(session.getAttribute(module+"_"+sub+"_get_record_result")!=null){ 167 | jsonObj=(JSONObject)session.getAttribute(module+"_"+sub+"_get_record_result"); 168 | }else{ 169 | //没有就报错 170 | jsonObj=new JSONObject(); 171 | jsonObj.put("result_code",10); 172 | jsonObj.put("result_msg","exist_resultset参数不当,服务器当前没有结果数据,请重新设置!"); 173 | } 174 | }else{ 175 | //如果是新查询 176 | FileDao fileDao=new FileDao(); 177 | jsonObj = fileDao.getRecord(query); 178 | session.setAttribute(module+"_"+sub+"_get_record_result",jsonObj); 179 | } 180 | jsonObj.put("userID",userId); 181 | //数据查询完毕,根据交互方式返回数据 182 | boolean isAjax=true; 183 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 184 | if(isAjax){ 185 | response.setContentType("application/json; charset=UTF-8"); 186 | try { 187 | PrintWriter out = response.getWriter(); 188 | out.print(jsonObj); //数据写入缓冲区 189 | out.flush(); 190 | out.close(); 191 | } catch (IOException e) { 192 | e.printStackTrace(); 193 | } 194 | }else{ 195 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 196 | int resultCode=0; 197 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 198 | //String url = redirectPath+"/"+redirectUrl; 199 | showDebug(resultMsg); 200 | //response.sendRedirect(url); 201 | } 202 | } 203 | 204 | public void deleteRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 205 | String flightID = request.getParameter("flightID"); 206 | String srcDate = request.getParameter("srcDate"); 207 | String srcTime = request.getParameter("srcTime"); 208 | JSONObject jsonObj=null; 209 | if(flightID!=null){ 210 | FileDao fileDao=new FileDao(); 211 | jsonObj=fileDao.deleteRecord(flightID, srcDate, srcTime); 212 | } 213 | boolean isAjax=true; 214 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 215 | if(isAjax){ 216 | response.setContentType("application/json; charset=UTF-8"); 217 | PrintWriter out; 218 | try { 219 | out = response.getWriter(); 220 | out.print(jsonObj); 221 | out.flush(); 222 | out.close(); 223 | } catch (IOException e){ 224 | e.printStackTrace(); 225 | } 226 | }else{ 227 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 228 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 229 | showDebug(resultMsg); 230 | } 231 | } 232 | 233 | public void modifyRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 234 | String flightID = request.getParameter("flightID"); 235 | String srcDate = request.getParameter("srcDate"); 236 | String dstDate = request.getParameter("dstDate"); 237 | String price = request.getParameter("price"); 238 | String srcTime = request.getParameter("srcTime"); 239 | String dstTime = request.getParameter("dstTime"); 240 | String company = request.getParameter("company"); 241 | String srcPlace = request.getParameter("srcPlace"); 242 | String dstPlace = request.getParameter("dstPlace"); 243 | String srcAirport = request.getParameter("srcAirport"); 244 | String dstAirport = request.getParameter("dstAirport"); 245 | FlightFile flightFile = new FlightFile(); 246 | flightFile.setDbName("FlightBooking"); 247 | flightFile.setFlightID(flightID); 248 | flightFile.setSrcDate(srcDate); 249 | flightFile.setDstDate(dstDate); 250 | flightFile.setPrice(price); 251 | flightFile.setSrcTime(srcTime); 252 | flightFile.setDstTime(dstTime); 253 | flightFile.setCompany(company); 254 | flightFile.setSrcPlace(srcPlace); 255 | flightFile.setDstPlace(dstPlace); 256 | flightFile.setSrcAirport(srcAirport); 257 | flightFile.setDstAirport(dstAirport); 258 | JSONObject jsonObj=null; 259 | if(flightID!=null){ 260 | FileDao fileDao=new FileDao(); 261 | jsonObj=fileDao.modifyRecord(flightFile, flightID, srcDate, srcTime); 262 | } 263 | boolean isAjax=true; 264 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 265 | if(isAjax){ 266 | response.setContentType("application/json; charset=UTF-8"); 267 | PrintWriter out; 268 | try { 269 | out = response.getWriter(); 270 | out.print(jsonObj); 271 | out.flush(); 272 | out.close(); 273 | } catch (IOException e){ 274 | e.printStackTrace(); 275 | } 276 | }else{ 277 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 278 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 279 | showDebug(resultMsg); 280 | } 281 | } 282 | 283 | public void addRecord(HttpServletRequest request, HttpServletResponse response) throws Exception { 284 | String flightID = request.getParameter("flightID"); 285 | String srcDate = request.getParameter("srcDate"); 286 | String dstDate = request.getParameter("dstDate"); 287 | String price = request.getParameter("price"); 288 | String srcTime = request.getParameter("srcTime"); 289 | String dstTime = request.getParameter("dstTime"); 290 | String company = request.getParameter("company"); 291 | String srcPlace = request.getParameter("srcPlace"); 292 | String dstPlace = request.getParameter("dstPlace"); 293 | String srcAirport = request.getParameter("srcAirport"); 294 | String dstAirport = request.getParameter("dstAirport"); 295 | FlightFile flightFile = new FlightFile(); 296 | flightFile.setDbName("FlightBooking"); 297 | flightFile.setFlightID(flightID); 298 | flightFile.setSrcDate(srcDate); 299 | flightFile.setDstDate(dstDate); 300 | flightFile.setPrice(price); 301 | flightFile.setSrcTime(srcTime); 302 | flightFile.setDstTime(dstTime); 303 | flightFile.setCompany(company); 304 | flightFile.setSrcPlace(srcPlace); 305 | flightFile.setDstPlace(dstPlace); 306 | flightFile.setSrcAirport(srcAirport); 307 | flightFile.setDstAirport(dstAirport); 308 | JSONObject jsonObj=null; 309 | if(flightID!=null){ 310 | FileDao fileDao=new FileDao(); 311 | jsonObj=fileDao.addRecord(flightFile); 312 | } 313 | boolean isAjax=true; 314 | if(request.getHeader("x-requested-with")==null){isAjax=false;} //判断是异步请求还是同步请求 315 | if(isAjax){ 316 | response.setContentType("application/json; charset=UTF-8"); 317 | PrintWriter out; 318 | try { 319 | out = response.getWriter(); 320 | out.print(jsonObj); 321 | out.flush(); 322 | out.close(); 323 | } catch (IOException e){ 324 | e.printStackTrace(); 325 | } 326 | }else{ 327 | String resultMsg="操作已经执行,请按返回按钮返回列表页面!"; 328 | resultMsg=java.net.URLEncoder.encode(resultMsg, "UTF-8"); 329 | showDebug(resultMsg); 330 | } 331 | } 332 | 333 | private String getRecordIndexFromId(String id,JSONObject json) throws JSONException{ 334 | String index="-1"; 335 | JSONArray jsonArr=(JSONArray)json.getJSONArray("aaData"); 336 | for(int i=0;i