public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception { ServiceDataForm obj = (ServiceDataForm) form; String serviceId = obj.getServiceId(); CalculateService obj2 = new CalculateService(); obj2.calculate(serviceId); Connection con = null; Class.forName(ConnectionStats.DRIVER); String url = ConnectionStats.DB_URL; String usr = ConnectionStats.DB_USER; String pwd = ConnectionStats.DB_PASSWORD; con = DriverManager.getConnection(url, usr, pwd); Statement stmt = con.createStatement(); ResultSet rs = null; rs = stmt.executeQuery("select * from " + serviceId + "_main"); ResultSetMetaData rsmd = rs.getMetaData(); int col = rsmd.getColumnCount(); String[] mainHeader = new String[col]; for (int i = 0; i < col; i++) { mainHeader[i] = rsmd.getColumnLabel(i + 1); } ArrayList<String[]> serviceDataMain = new ArrayList<String[]>(); while (rs.next()) { String[] str = new String[col]; for (int i = 0; i < col; i++) { str[i] = rs.getString(i + 1); } serviceDataMain.add(str); } req.setAttribute("mainHeader", mainHeader); req.setAttribute("serviceDataMain", serviceDataMain); rs = stmt.executeQuery("select * from " + serviceId + "_tbl"); rsmd = rs.getMetaData(); col = rsmd.getColumnCount(); String[] tblHeader = new String[col]; for (int i = 0; i < col; i++) { tblHeader[i] = rsmd.getColumnLabel(i + 1); } ArrayList<String[]> serviceDatatbl = new ArrayList<String[]>(); while (rs.next()) { String[] str = new String[col]; for (int i = 0; i < col; i++) { str[i] = rs.getString(i + 1); } serviceDatatbl.add(str); } req.setAttribute("tblHeader", tblHeader); req.setAttribute("serviceDatatbl", serviceDatatbl); rs.close(); con.close(); return mapping.findForward("success"); }
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { try { ConnectionPool conPool = getConnectionPool(); if (!realAuthentication(request, conPool)) { String queryString = request.getQueryString(); if (request.getQueryString() == null) { queryString = ""; } // if user is not authenticated send to signin response.sendRedirect( response.encodeRedirectURL(URLAUTHSIGNIN + "?" + URLBUY + "?" + queryString)); } else { response.setHeader("Cache-Control", "no-cache"); response.setHeader("Expires", "0"); response.setHeader("Pragma", "no-cache"); response.setContentType("text/html"); String errorMessage = processRequest(request, response, conPool); if (errorMessage != null) { request.setAttribute(StringInterface.ERRORPAGEATTR, errorMessage); RequestDispatcher rd = getServletContext().getRequestDispatcher(PATHUSERERROR); rd.include(request, response); } } } catch (Exception e) { throw new ServletException(e); } }
/** * This calls the itemselection.jsp and list all items available for a WorkOrder and a WorkOrder's * item list * * @param workorderid - the WO_ID of the parent WorkOrder * @param request - servlet request * @param response - servlet response */ private void listProducts( long workorderId, WorkOrderDetailRemote workorderdetEJBean, HttpSession session, HttpServletRequest req, HttpServletResponse resp) { try { // If any product object is left over in session remove it session.removeValue("itemObj"); // Create db connection for EJB workorderdetEJBean.connect(); // Get the 2D Array which has the List of Items for the WorkOrder // grouped by the Billing System. Object[][] productList = workorderdetEJBean.getWorkOrderItems(workorderId); // Get the WorkOrder Object WorkOrder workorderObj = workorderdetEJBean.getWorkOrderInfo(workorderId); // Get the List of all Product Names for the WorkOrder String[] productNameList = workorderdetEJBean.getProdList(workorderId); for (int w = 0; w < productNameList.length; w++) USFEnv.getLog() .writeDebug("VALUES INSIDE productNameList is" + productNameList[w], this, null); // Set the attributes to the itemselection JSP req.setAttribute("productNameList", productNameList); req.setAttribute("productList", productList); req.setAttribute("workorderObj", workorderObj); // Release db connection for EJB workorderdetEJBean.release(); // Include the JSP includeJSP(req, resp, ITEM_JSP_PATH, "itemselection"); return; } catch (Exception e) { String errorMsg = "Fail to list products for a WORKORDER " + workorderId; USFEnv.getLog().writeCrit(errorMsg, this, e); errorJSP(req, resp, errorMsg); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) { try { request.setAttribute("body", "/WEB-INF/jsp/testimonial.jsp"); layoutPage.forward(request, response); } catch (Exception e) { e.printStackTrace(); } }
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String nombreChofer = request.getParameter("nombreChofer"); String telefonoChofer = request.getParameter("telefonoChofer"); float salarioChofer = Float.parseFloat(request.getParameter("salarioChofer")); String choferID = request.getParameter("usernameChofer"); Chofer c = new Chofer(nombreChofer, telefonoChofer, salarioChofer); new ListaChoferes().updateChofer(choferID, c); request.setAttribute("mensaje", "Chofer modificado de manera exitosa"); String color = "10E214"; request.setAttribute("coloreado", color); request.setAttribute("ListaDeChoferes", new ListaChoferes().obtenerChoferes()); request.getRequestDispatcher("VerChoferes.jsp").forward(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer etat = (Integer) request.getSession().getAttribute("etat"); if (etat == null) { RequestDispatcher dispatcher = request.getRequestDispatcher("/login.jsp"); dispatcher.forward(request, response); } else { try { String titre = request.getParameter("titre"); String dateSortie = request.getParameter("dateSortie"); String nom = request.getParameter("nom"); String role = request.getParameter("role"); // conversion du parametre dateSortie en SQLDate Date date; try { date = new Date(FormatDate.convertirDate(dateSortie).getTime()); } catch (ParseException e) { throw new Tp6Exception( "Format de la date " + dateSortie + " incorrect. AAAA-MM-JJ attendue."); } // executer la transaction GestionTp6 tp6Update = (GestionTp6) request.getSession().getAttribute("tp6Update"); synchronized (tp6Update) { tp6Update.gestionFilm.ajoutActeurFilm(titre, date, nom, role); } RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/menu.jsp"); dispatcher.forward(request, response); } catch (Tp6Exception e) { List<String> listeMessageErreur = new LinkedList<String>(); listeMessageErreur.add(e.toString()); request.setAttribute("listeMessageErreur", listeMessageErreur); RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/menu.jsp"); dispatcher.forward(request, response); } catch (Exception e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); } } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); HttpSession session = request.getSession(false); String reseller = null; if (session != null && session.getAttribute("reseller") != null) reseller = "%" + session.getAttribute("reseller") + "%"; List<LicenseData> searchResult = null; if (reseller != null) { /* session.setAttribute("fieldsearch", true); session.removeAttribute("datesearch");*/ if (request.getParameter("so") != null && !request.getParameter("so").isEmpty()) { log.info( "Search Fields : Sales Order Search " + request.getParameter("so") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("so"), "so"); session.setAttribute("so", request.getParameter("so")); session.removeAttribute("enduser"); session.removeAttribute("ek"); session.setAttribute("label", "Sales Order"); session.setAttribute("value", request.getParameter("so")); } else if (request.getParameter("enduser") != null && !request.getParameter("enduser").isEmpty()) { log.info( "Search Fields : End User Search " + request.getParameter("enduser") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("enduser"), "enduser"); session.setAttribute("enduser", request.getParameter("enduser")); session.removeAttribute("so"); session.removeAttribute("sno"); session.removeAttribute("ek"); session.setAttribute("label", "End User"); session.setAttribute("value", request.getParameter("enduser")); } else if (request.getParameter("ek") != null && !request.getParameter("ek").isEmpty()) { log.info( "Search Fields : Entitlement Key Search " + request.getParameter("ek") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("ek"), "ek"); session.setAttribute("ek", request.getParameter("ek")); session.removeAttribute("so"); session.removeAttribute("sno"); session.removeAttribute("enduser"); session.setAttribute("label", "Entitlement Key"); session.setAttribute("value", request.getParameter("ek")); } else if (request.getParameter("sno") != null && !request.getParameter("sno").isEmpty()) { log.info( "Search Fields : Serial Number Search " + request.getParameter("sno") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("sno"), "sno"); session.setAttribute("sno", request.getParameter("sno")); session.removeAttribute("ek"); session.removeAttribute("so"); session.removeAttribute("enduser"); request.setAttribute("sno", 1); session.setAttribute("label", "Serial Number"); session.setAttribute("value", request.getParameter("sno")); } else if (request.getParameter("po") != null && !request.getParameter("po").isEmpty()) { log.info( "Search Fields : Purchase Order Search " + request.getParameter("po") + " for reseller " + session.getAttribute("reseller")); searchResult = getSearchByFieldResults(reseller, request.getParameter("po"), "po"); session.setAttribute("po", request.getParameter("po")); session.setAttribute("label", "Purchase Order"); session.setAttribute("value", request.getParameter("po")); } else if (request.getParameter("hm") != null && !request.getParameter("hm").isEmpty()) { log.info( "Search Fields : HM ID Search " + request.getParameter("hm") + " for reseller " + session.getAttribute("hm")); searchResult = getSearchByFieldResults(reseller, request.getParameter("hm"), "hm"); session.setAttribute("hm", request.getParameter("hm")); session.setAttribute("label", "Hive Manager ID"); session.setAttribute("value", request.getParameter("hm")); } session.setAttribute("fieldSearchList", searchResult); String nextJSP = "/viewFieldSearchResult.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request, response); } else { log.info("Search Fields : Reseller Blank "); String nextJSP = "/login.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request, response); } }
// 一周内的污染源在线脱机联机报表 public static void run7(HttpServletRequest req) throws Exception { String gas_station_type = "2"; String water_station_type = "1"; String so2_col = "val01"; String cod_col = "val02"; Connection cn = null; String sql = null; List list = new ArrayList(); // 存储这周内的数据 List list2 = new ArrayList(); // 存储今天的数据 List list3 = new ArrayList(); // 存储脱机的数据 List l_temp = null; List td_temp = null; // 存储今天的数据 String kv = null; String kv_2 = null; Map tmp = null; Map tmp_2 = null; Map tmp2 = new HashMap(); Map tmp3 = new HashMap(); Map data = null; // 存这周内有数据的站位 Map data2 = null; // 存储今天的数据 Map data3 = null; // 存储这周脱机的站位 List waterStationList = null; List gasStationList = null; // String date = req.getParameter("date"); String now = StringUtil.getNowDate() + ""; // String now = req.getParameter("date")+"";//黄宝修改 String date1, date2 = null; // 从现在开始,退后7天。 Calendar cal = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); cal.setTime(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, -7); // 退后7天 String now_7 = sdf.format(cal.getTime()); cal2.setTime(cal2.getTime()); cal2.add(Calendar.DAY_OF_MONTH, -1); // 退后1天 String now_1 = sdf.format(cal2.getTime()) + " 23:59:59"; ; date1 = sdf.format(cal2.getTime()) + " 23:59:59"; date2 = now_7 + ""; Map areaMap = null; Map bean = new HashMap(); int i, num = 0; Map m = null; String area_id = null; try { area_id = req.getParameter("area_id"); if (area_id == null) { area_id = ""; } // date1 = req.getParameter("date1"); // date1 = req.getParameter("date1"); sql = "select station_id,m_time," + so2_col + "," + cod_col + " from " + req.getParameter("tableName"); sql = sql + " where m_time>='" + date2 + "' and m_time<='" + date1 + "'"; sql = sql + " and station_id in ("; sql = sql + "select station_id from t_cfg_station_info where station_type in ('1','2') and area_id like '" + area_id + "%') order by m_time desc"; // System.out.println(sql); cn = f.getConn(); // System.out.println(sql); l_temp = f.query(cn, sql, null); // 最近一周的数据 num = l_temp.size(); for (i = 0; i < num; i++) { tmp = (Map) l_temp.get(i); kv = (String) tmp.get("station_id"); String station_id_t = (String) tmp2.get(kv); if ("".equals(station_id_t) || station_id_t == null) { list.add(tmp); // 最近一周都有的数据 tmp2.put(kv, kv); } } // data = f.getListMap(list,"station_id");//最近一周都有的数据 // 查询今天有数据的站位 String now_time = StringUtil.getNowDate() + ""; date1 = now_time + ""; date2 = now_time + " 23:59:59"; sql = "select station_id,m_time," + so2_col + "," + cod_col + " from " + req.getParameter("tableName"); sql = sql + " where m_time>='" + date1 + "' and m_time<='" + date2 + "'"; sql = sql + " and station_id in ("; sql = sql + "select station_id from t_cfg_station_info where station_type in ('1','2') and area_id like '" + area_id + "%') order by m_time desc"; td_temp = f.query(cn, sql, null); // 今天的数据 tmp2 = null; num = td_temp.size(); for (i = 0; i < num; i++) { tmp = (Map) td_temp.get(i); kv = (String) tmp.get("station_id"); String station_id_t = (String) tmp3.get(kv); if ("".equals(station_id_t) || station_id_t == null) { list2.add(tmp); // 今天有数据的站位。 tmp3.put(kv, kv); } } // 循环这一周内有数据的站位列表list,如果list中的站位不能在今天的站位信息列表中list2中找到的话,则表明是脱机 num = list.size(); int j = 0; int num2 = list2.size(); String station_id_1 = ""; String station_id_2 = ""; int l = 0; for (i = 0; i < num; i++) { tmp = (Map) list.get(i); station_id_1 = (String) tmp.get("station_id"); l = 0; for (j = 0; j < num2; j++) { tmp_2 = (Map) list2.get(j); station_id_2 = (String) tmp_2.get("station_id"); if (station_id_1.equals(station_id_2)) { l++; } } if (l == 0) { list3.add(tmp); } } data = f.getListMap(list3, "station_id"); // 这周脱机的站位信息列表 l_temp = null; tmp = null; list2 = null; list3 = null; tmp_2 = null; tmp3 = null; sql = "select station_id,station_desc,ep_type,area_id,station_bz from t_cfg_station_info where station_type='1' and area_id like '" + area_id + "%' order by area_id,station_desc"; waterStationList = f.query(cn, sql, null); // System.out.println(sql); sql = "select station_id,station_desc,ep_type,area_id from t_cfg_station_info where station_type='2' and area_id like '" + area_id + "%' order by area_id,station_desc"; gasStationList = f.query(cn, sql, null); // System.out.println(sql); sql = "select area_id,area_name from t_cfg_area"; areaMap = f.getMap(cn, sql); // System.out.println(sql); num = waterStationList.size(); for (i = 0; i < num; i++) { m = (Map) waterStationList.get(i); area_id = (String) m.get("area_id"); m.put("area_name", areaMap.get(area_id)); } num = gasStationList.size(); for (i = 0; i < num; i++) { m = (Map) gasStationList.get(i); area_id = (String) m.get("area_id"); m.put("area_name", areaMap.get(area_id)); } // System.out.println("before close,cn="+cn); f.close(cn); // System.out.println("after close,cn="+cn); int waterOnlineNum, gasOnlineNum, onlineNum = 0; int waterOfflineNum, gasOfflineNum, offlineNum = 0; int waterOfflineNumNation, gasOfflineNumNation, offlineNumNation = 0; int waterZeroNum, gasZeroNum, zeroNum = 0; int waterZeroNumNation, gasZeroNumNation, zeroNumNation = 0; waterOnlineNum = OnlineReport.getOnlineNum(waterStationList, data); gasOnlineNum = OnlineReport.getOnlineNum(gasStationList, data); onlineNum = waterOnlineNum + gasOnlineNum; // System.out.println(onlineNum); waterOfflineNum = OnlineReport.getOfflineNum(waterStationList, data); gasOfflineNum = OnlineReport.getOfflineNum(gasStationList, data); offlineNum = waterOfflineNum + gasOfflineNum; // System.out.println("zeroNumNation "+zeroNumNation); waterOfflineNumNation = OnlineReport.getOfflineNumNation(waterStationList, data); gasOfflineNumNation = OnlineReport.getOfflineNumNation(gasStationList, data); offlineNumNation = waterOfflineNumNation + gasOfflineNumNation; // System.out.println("offlineNumNation "+offlineNumNation); waterZeroNum = OnlineReport.getZeroNum(waterStationList, data, cod_col); gasZeroNum = OnlineReport.getZeroNum(gasStationList, data, so2_col); zeroNum = waterZeroNum + gasZeroNum; // System.out.println(zeroNum); waterZeroNumNation = OnlineReport.getZeroNumNation(waterStationList, data, cod_col); gasZeroNumNation = OnlineReport.getZeroNumNation(gasStationList, data, so2_col); zeroNumNation = waterZeroNumNation + gasZeroNumNation; // System.out.println(zeroNumNation); bean.put("waterOnlineNum", waterOnlineNum + ""); bean.put("gasOnlineNum", gasOnlineNum + ""); bean.put("onlineNum", onlineNum + ""); bean.put("waterOfflineNum", waterOfflineNum + ""); bean.put("gasOfflineNum", gasOfflineNum + ""); bean.put("offlineNum", offlineNum + ""); bean.put("waterOfflineNumNation", waterOfflineNumNation + ""); bean.put("gasOfflineNumNation", gasOfflineNumNation + ""); bean.put("offlineNumNation", offlineNumNation + ""); bean.put("waterZeroNum", waterZeroNum + ""); bean.put("gasZeroNum", gasZeroNum + ""); bean.put("zeroNum", zeroNum + ""); bean.put("waterZeroNumNation", waterZeroNumNation + ""); bean.put("gasZeroNumNation", gasZeroNumNation + ""); bean.put("zeroNumNation", zeroNumNation + ""); date1 = now_7; date2 = StringUtil.getNowDate() + ""; bean.put("date1", date2); bean.put("date2", date1); req.setAttribute("bean", bean); list = getOfflineList2(waterStationList, data); req.setAttribute("waterOfflineList", list); list = getOfflineList2(gasStationList, data); req.setAttribute("gasOfflineList", list); list = getOfflineListNation(waterStationList, data); req.setAttribute("waterOfflineListNation", list); list = getOfflineListNation(gasStationList, data); req.setAttribute("gasOfflineListNation", list); list = getZeroListNation(waterStationList, data, cod_col); req.setAttribute("waterZeroListNation", list); list = getZeroListNation(gasStationList, data, so2_col); req.setAttribute("gasZeroListNation", list); } catch (Exception e) { throw e; } finally { f.close(cn); } }
public static void run(HttpServletRequest req) throws Exception { String gas_station_type = "2"; String water_station_type = "1"; String so2_col = "val01"; String cod_col = "val02"; Connection cn = null; String sql = null; List list = null; Map data = null; List waterStationList = null; List gasStationList = null; // String date = req.getParameter("date"); // String now = StringUtil.getNowDate()+""; String now = req.getParameter("date") + ""; // 黄宝修改 String date1, date2 = null; Map areaMap = null; Map bean = new HashMap(); date1 = now + ""; date2 = now + " 23:59:59"; int i, num = 0; Map m = null; String area_id = null; try { area_id = req.getParameter("area_id"); if (area_id == null) { area_id = ""; } // date1 = req.getParameter("date1"); // date1 = req.getParameter("date1"); sql = "select station_id," + so2_col + "," + cod_col + " from " + req.getParameter("tableName"); sql = sql + " where m_time>='" + date1 + "' and m_time<='" + date2 + "'"; sql = sql + " and station_id in ("; sql = sql + "select station_id from t_cfg_station_info where station_type in ('1','2') and area_id like '" + area_id + "%')"; // System.out.println(sql); cn = f.getConn(); // System.out.println(sql); list = f.query(cn, sql, null); data = f.getListMap(list, "station_id"); sql = "select station_id,station_desc,ep_type,area_id,station_bz from t_cfg_station_info where station_type='1' and area_id like '" + area_id + "%' order by area_id,station_desc"; waterStationList = f.query(cn, sql, null); // System.out.println(sql); sql = "select station_id,station_desc,ep_type,area_id from t_cfg_station_info where station_type='2' and area_id like '" + area_id + "%' order by area_id,station_desc"; gasStationList = f.query(cn, sql, null); // System.out.println(sql); sql = "select area_id,area_name from t_cfg_area"; areaMap = f.getMap(cn, sql); // System.out.println(sql); num = waterStationList.size(); for (i = 0; i < num; i++) { m = (Map) waterStationList.get(i); area_id = (String) m.get("area_id"); m.put("area_name", areaMap.get(area_id)); } num = gasStationList.size(); for (i = 0; i < num; i++) { m = (Map) gasStationList.get(i); area_id = (String) m.get("area_id"); m.put("area_name", areaMap.get(area_id)); } // System.out.println("before close,cn="+cn); f.close(cn); // System.out.println("after close,cn="+cn); int waterOnlineNum, gasOnlineNum, onlineNum = 0; int waterOfflineNum, gasOfflineNum, offlineNum = 0; int waterOfflineNumNation, gasOfflineNumNation, offlineNumNation = 0; int waterZeroNum, gasZeroNum, zeroNum = 0; int waterZeroNumNation, gasZeroNumNation, zeroNumNation = 0; waterOnlineNum = OnlineReport.getOnlineNum(waterStationList, data); gasOnlineNum = OnlineReport.getOnlineNum(gasStationList, data); onlineNum = waterOnlineNum + gasOnlineNum; // System.out.println(onlineNum); waterOfflineNum = OnlineReport.getOfflineNum(waterStationList, data); gasOfflineNum = OnlineReport.getOfflineNum(gasStationList, data); offlineNum = waterOfflineNum + gasOfflineNum; // System.out.println("zeroNumNation "+zeroNumNation); waterOfflineNumNation = OnlineReport.getOfflineNumNation(waterStationList, data); gasOfflineNumNation = OnlineReport.getOfflineNumNation(gasStationList, data); offlineNumNation = waterOfflineNumNation + gasOfflineNumNation; // System.out.println("offlineNumNation "+offlineNumNation); waterZeroNum = OnlineReport.getZeroNum(waterStationList, data, cod_col); gasZeroNum = OnlineReport.getZeroNum(gasStationList, data, so2_col); zeroNum = waterZeroNum + gasZeroNum; // System.out.println(zeroNum); waterZeroNumNation = OnlineReport.getZeroNumNation(waterStationList, data, cod_col); gasZeroNumNation = OnlineReport.getZeroNumNation(gasStationList, data, so2_col); zeroNumNation = waterZeroNumNation + gasZeroNumNation; // System.out.println(zeroNumNation); bean.put("waterOnlineNum", waterOnlineNum + ""); bean.put("gasOnlineNum", gasOnlineNum + ""); bean.put("onlineNum", onlineNum + ""); bean.put("waterOfflineNum", waterOfflineNum + ""); bean.put("gasOfflineNum", gasOfflineNum + ""); bean.put("offlineNum", offlineNum + ""); bean.put("waterOfflineNumNation", waterOfflineNumNation + ""); bean.put("gasOfflineNumNation", gasOfflineNumNation + ""); bean.put("offlineNumNation", offlineNumNation + ""); bean.put("waterZeroNum", waterZeroNum + ""); bean.put("gasZeroNum", gasZeroNum + ""); bean.put("zeroNum", zeroNum + ""); bean.put("waterZeroNumNation", waterZeroNumNation + ""); bean.put("gasZeroNumNation", gasZeroNumNation + ""); bean.put("zeroNumNation", zeroNumNation + ""); req.setAttribute("bean", bean); list = getOfflineList(waterStationList, data); req.setAttribute("waterOfflineList", list); list = getOfflineList(gasStationList, data); req.setAttribute("gasOfflineList", list); list = getOfflineListNation(waterStationList, data); req.setAttribute("waterOfflineListNation", list); list = getOfflineListNation(gasStationList, data); req.setAttribute("gasOfflineListNation", list); list = getZeroListNation(waterStationList, data, cod_col); req.setAttribute("waterZeroListNation", list); list = getZeroListNation(gasStationList, data, so2_col); req.setAttribute("gasZeroListNation", list); } catch (Exception e) { throw e; } finally { f.close(cn); } }
/** * 查询处理 * * @param actionForm ActionForm 表单From * @param request HttpServletRequest Web请求 * @param response HttpServletResponse Web结果 * @throws CDealException 处理异常 */ public static void doQuery( QueryForm pQueryForm, HttpServletRequest request, HttpServletResponse response) throws CDealException { try { // 查询数据SQL语句 String msSql = "select CHENGPIID,COMPLAINEDPERSON,COMPLAINPERSON,COMPLAINVERSION,to_char(a.CREATEDATE,'yyyy-mm-dd')CREATEDATE,COMPLAINUNIT,COMPLAINEDUNIT,SPARE1,SPARE2,SPARE3,SPARE4,t.abbrname,a.XZGCXYFL,a.SUBXZGCXYFL from T_YW_ZDSX_JCJ_TSCHENGPIBIAO a,t_Sys_Department t WHERE a.STATUS = 1 and SUBMITSTATUS = 1 and t.id=COMPLAINEDUNIT "; // 主查询语句 String msOrder = "ORDER BY CREATEDATE desc"; // 排序语句 // 查询子条件 String msSqlWhere = ""; String msTemp = pQueryForm.getCHENGPIID(); // 呈批表编号 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and CHENGPIID like '%" + msTemp + "%'"; } msTemp = pQueryForm.getCOMPLAINEDPERSON(); // 呈批表被投诉人姓名 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and COMPLAINEDPERSON like '%" + msTemp + "%'"; } msTemp = pQueryForm.getCOMPLAINUNIT(); // 呈批表问题性质 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and COMPLAINUNIT like '%" + msTemp + "%'"; } msTemp = pQueryForm.getCOMPLAINEDUNIT(); // 呈批表被投诉人单位 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and COMPLAINEDUNIT = '" + msTemp + "'"; } msTemp = pQueryForm.getCOMPLAINPERSON(); // 呈批表投诉人姓名 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and COMPLAINPERSON like '%" + msTemp + "%'"; } msTemp = pQueryForm.getCOMPLAINVERSION(); // 呈批表投诉形式 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and COMPLAINVERSION =" + msTemp; } msTemp = pQueryForm.getCREATEDATE1(); // 呈批表创建时间,起 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and CREATEDATE >= to_date('" + msTemp + "','yyyy-mm-dd')"; } msTemp = pQueryForm.getCREATEDATE2(); // 呈批表创建时间,止 if (msTemp != null && msTemp.length() > 0) { msSqlWhere += " and CREATEDATE <= to_date('" + msTemp + "','yyyy-mm-dd')"; } msSql = msSql + msSqlWhere; // 主查询语句 加上 查询子条件 CDataPage dataPage = new CDataPage(); // 翻页实现类 dataPage.setQuerySql(msSql); // 设置查询语句 dataPage.setOrderStr(msOrder); // 设置排序语句 dataPage.setPageRowCount(CConstants.PAGE_ROW_COUNT); // 每页行数 dataPage.init(request); request.setAttribute(CConstants.DATA_PAGE_OBJECT, dataPage); // 初始化页面,初始化投诉形式下拉菜单 TreeMap COMPLAINVERSIONListName = new TreeMap(); // 取出aWebForm COMPLAINVERSIONListName = CCodeMap.getMapByType("行政效能投诉形式"); pQueryForm.setCOMPLAINVERSIONList(COMPLAINVERSIONListName); TreeMap COMPLAINVERSIONListName1 = new TreeMap(); // 取出aWebForm COMPLAINVERSIONListName1 = CCodeMap.getMapByType("部门名称列表"); pQueryForm.setDepartList(COMPLAINVERSIONListName1); } catch (Exception e) { throw new CDealException("根据输入条件进行查询时失败。", e); } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub boolean isSussed = false; LogClass RegisterBean = new LogClass(); // 创建javabean模型 request.setAttribute("RegisterBean", RegisterBean); // 将会更新id是userBean的bean String logname = request.getParameter("sign_name").trim(); String logpassword = request.getParameter("sign_password").trim(); String logpassword2 = request.getParameter("sign_confirm_password").trim(); if (logname == null) logname = ""; if (logpassword == null) logpassword = ""; if (!logpassword.equals(logpassword2)) { RegisterBean.setBackNews("两次密码不同,注册失败啦!要认真填哦!"); RegisterBean.setSucced(false); isSussed = false; RequestDispatcher dispatcher = request.getRequestDispatcher("join.jsp"); dispatcher.forward(request, response); // 转发 return; } // 注册信息合法检查 if (logname.length() > 0 && logpassword.length() > 5) { // 信息合法 if (!getConnection.getConnection()) { // 连接数据库失败 RegisterBean.setBackNews("数据库连接失败,数据库现在无法服务哦!!"); RequestDispatcher dispatcher = request.getRequestDispatcher("join.jsp"); dispatcher.forward(request, response); // 转发 return; } try { String insertCondition = "INSERT INTO usr VALUES(?,?,?,?);"; getConnection.prepareStatement(insertCondition); getConnection.getSql().setString(1, handleString(logname)); getConnection.getSql().setString(2, handleString(logpassword)); getConnection.getSql().setString(3, "user_"); getConnection.getSql().setString(4, "true_"); if (getConnection.getSql().executeUpdate() != 0) { RegisterBean.setBackNews("注册成功,用户名为:" + handleString(logname) + "密码:" + logpassword); RegisterBean.setSucced(true); isSussed = true; RegisterBean.setName(logname); RegisterBean.setPassword(logpassword); } } catch (SQLException e) { // TODO Auto-generated catch block // e.printStackTrace(); RegisterBean.setBackNews("用户名已经存在或格式有问题哟,请重新填写信息!"); RegisterBean.setSucced(false); isSussed = false; } } else if (logname.length() <= 0) { RegisterBean.setBackNews("用户名长度不够,请重新填写哦!"); RegisterBean.setSucced(false); isSussed = false; } else if (logpassword.length() < 6) { RegisterBean.setBackNews("密码长度不够,请重新填写哦!"); RegisterBean.setSucced(false); isSussed = false; } else { // 信息不合法 RegisterBean.setBackNews("信息填写不完整或名字中有非法字,请重新填写哦!"); RegisterBean.setSucced(false); isSussed = false; } if (!isSussed) { RequestDispatcher dispatcher = request.getRequestDispatcher("join.jsp"); dispatcher.forward(request, response); // 转发 } else { RequestDispatcher dispatcher = request.getRequestDispatcher("hint.jsp"); dispatcher.forward(request, response); // 转发 } }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("gb2312"); response.setContentType("text/html; charset=gb2312"); out = response.getWriter(); session = request.getSession(); time = new Time(); str = new Str(); db = new Db(); // 取得 try { id = Integer.parseInt((String) request.getParameter("id")); } catch (Exception e) { id = 0; } password = request.getParameter("password"); password = str.inStr(password); sqlsp = "SELECT * FROM password WHERE employeeid=" + id; sqlse = "SELECT employeeid FROM eminfo WHERE employeeid=" + id; sqlu = "UPDATE password SET time='" + time.getYMDHMS() + "',password='******' WHERE employeeid=" + id; sqli = "INSERT INTO password(employeeid,password,time) VALUES(" + id + ",'" + password + "','" + time.getYMDHMS() + "')"; try { stmt = db.getStmtread(); rs = stmt.executeQuery(sqlsp); // 不是第一次设置更新数据库 if (rs.next()) { db.close(); stmt = db.getStmt(); temp = 0; temp = stmt.executeUpdate(sqlu); if (temp > 0) { request.setAttribute("msg", "设置成功"); } else { request.setAttribute("msg", "设置失败"); } db.close(); } else { // 第一次设置 db.close(); temp = 0; stmt = db.getStmtread(); rs = stmt.executeQuery(sqlse); if (rs.next()) { // id存在 rs.close(); stmt.close(); temp = 0; stmt = db.getStmt(); temp = stmt.executeUpdate(sqli); if (temp > 0) { request.setAttribute("msg", "设置成功"); } else { request.setAttribute("msg", "设置失败"); } db.close(); } else { // id不存在 db.close(); request.setAttribute("msg", "员工序号不存在"); } } } catch (SQLException e) { e.printStackTrace(); } finally { RequestDispatcher dispatcher = request.getRequestDispatcher("set1.jsp"); dispatcher.forward(request, response); } }
/** * This is the main controller logic for item selection servlet. This determines whether to show a * list of items for a WorkOrder, add a item, edit a item's detail information, or delete a item. * The product_action parameter is past to this servlet to determine what action to perform. The * product_action parameter is a button defined by JSPs related to product presentation screens. * * <p>The default action is to show all product related to a parent WorkOrder. * * @param req HttpServlet request * @param resp HttpServlet response */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { WorkOrderDetailRemote workorderdetEJBean = null; securityChecks(req, resp); // Get the current session HttpSession session = req.getSession(false); if (session == null) return; String sTmp = ""; // Get a new business logic EJB (custInfoEJBean) USFEnv.getLog().writeDebug("getting buslogic EJB", this, null); try { workorderdetEJBean = workorderdetHome.create(); USFEnv.getLog().writeDebug("EJBean Created", this, null); } catch (CreateException e) { String errorMsg = "Critical Exception in ItemsServlet"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e); errorJSP(req, resp, errorMsg); return; } catch (RemoteException e) { String errorMsg = "Critical Exception in ItemsServlet"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB connect", this, e); errorJSP(req, resp, errorMsg); return; } catch (Exception e) { String errorMsg = "Critical Exception no EJB created"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e); errorJSP(req, resp, errorMsg); return; } try { // Button user pressed in the itemselection.jsp String sJSPAction = req.getParameter("product_action"); USFEnv.getLog().writeWarn("product_action from JSP: " + sJSPAction, this, null); short year = Short.valueOf((String) session.getValue("Iyear")).shortValue(); long customerId = Long.valueOf((String) session.getValue("rcustId")).longValue(); long applicationId = Long.valueOf((String) session.getValue("rappid")).longValue(); long workorderId = 0; long bkId = 0; long billkeyId = 0; long bsId = 0; long wodId = 0; String editflag = ""; String bsNm = ""; java.sql.Date strtDate = null; java.sql.Date endDate = null; String prodError = ""; // Check to make sure session does have an WorkOrder ID if (session.getValue("WorkOrderId") != null) { // If Yes get the parent WorkOrder ID from session workorderId = Long.valueOf((String) session.getValue("WorkOrderId")).longValue(); } // Button Action from JSP is empty then show the Default page of the // Product Listing. if (USFUtil.isBlank(sJSPAction)) { USFEnv.getLog().writeDebug("Display product list for FRN.", this, null); // list items for parent Work Order Number Vector billingsystems = null; WrkOrdrDets workorderdets = new WrkOrdrDets(); billingsystems = workorderdets.getBillingSystems(); req.setAttribute("BillingSystems", billingsystems); for (int s = 0; s < billingsystems.size(); s++) USFEnv.getLog() .writeDebug("INSIDE BILLING SYSTEMS " + billingsystems.elementAt(s), this, null); listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } // Button action from JSP is to Add a new Item else if (sJSPAction.equals("add")) { // Remove the Product Object from session session.removeValue("prodObj"); editflag = "addnew"; req.setAttribute("editflag", editflag); // Read the Item and the Billing System for adding the New // Item. String formProdBsId = (String) req.getParameter("formProdId"); String formProdId = formProdBsId.substring(0, formProdBsId.indexOf("|")); String formProdName = formProdBsId.substring(formProdBsId.indexOf("|") + 1); long rscId = (new Long(formProdId).longValue()); // bsId = (new Long( formBsId ).longValue()) ; String billSystem = formProdName.substring(0, formProdName.indexOf("-")); String itemName = formProdName.substring(formProdName.indexOf("-") + 1); BlgSys blgSys = new BlgSys(); bsId = blgSys.getBsId(billSystem); // Create db connection for EJB workorderdetEJBean.connect(); // Get the WorkOrder Object. WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId); // Get the list of Billing Keys for the Billing System. String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId); // Release db connection for EJB workorderdetEJBean.release(); // If no Billing Keys for the Billing System selected then redirect // to the List Items screen and show the error Message. if (blgKeys == null) { BlgSys blgsys = new BlgSys(); Hashtable bSysList = (Hashtable) blgsys.searchBlgSys(); // Hashtable bSysList = (Hashtable) USFEnv.getBillSystems(); // Set the JSP error message req.setAttribute("errorMsg", "No BTNs for Billing System " + billSystem); // list products for parent WorkOrder Number listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } req.setAttribute("prodcredit", "N"); req.setAttribute("bsystem", String.valueOf(bsId)); req.setAttribute("bkList", blgKeys); req.setAttribute("prodId", formProdId); String wid = String.valueOf(workorderId); session.putValue("workorderId", wid); req.setAttribute("billingsystem", billSystem); req.setAttribute("itemname", itemName); // Include the JSP to Edit Product includeJSP(req, resp, ITEM_JSP_PATH, "editItem"); return; } // Button action from JSP is to Edit a Product else if (sJSPAction.equals("edit")) { String bsysid = req.getParameter("bsId"); session.putValue("bysysidforedit", bsysid); wodId = (new Long((String) req.getParameter("wodId"))).longValue(); // bkId = (new Long( (String) req.getParameter("bkId"))).longValue() ; session.putValue("workorderdetid", String.valueOf(wodId)); bsId = (new Long((String) req.getParameter("bsId"))).longValue(); BlgSys blgSys = new BlgSys(); bsNm = blgSys.getBsName(bsId); // Create db connection for EJB workorderdetEJBean.connect(); // WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId); // Get the WorkOrder Number Object WrkOrdrDets wodets_obj = new WrkOrdrDets(); wodets_obj = workorderdetEJBean.getProductInfo(wodId); // Get the List of Billing Keys for the Billing System. String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId); // Check if the Item has any Credits. If any credits then Billing // Key is not Editable else Editable. if (workorderdetEJBean.hasCredits(wodId)) { req.setAttribute("prodcredit", "Y"); } else { req.setAttribute("prodcredit", "N"); } // Release db connection for EJB workorderdetEJBean.release(); // If Item Object is not null (which generally is the case) then // set the Attributes for the JSP. if (wodets_obj != null) { // Put the Item Object in session editflag = "edit"; session.putValue("wodets", wodets_obj); req.setAttribute("editflag", editflag); // Set the attributes for the Billing System, Billing Key List, req.setAttribute("bkList", blgKeys); req.setAttribute("bsname", bsNm); // Include the JSP to Edit the Item. includeJSP(req, resp, ITEM_JSP_PATH, "editItem"); return; } // If Item Object is null (which generally should not Occur) show // the Default page of Item List for the WorkOrder Number else { // Set the JSP error message req.setAttribute( "errorMsg", "Product Key - " + wodId + " Information not available in the Data Base"); // list items for parent WorkOrder Number listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } } // Button action from JSP is to Delete an Item else if (sJSPAction.equals("delete")) { String formWodId = req.getParameter("wodId"); wodId = (new Long((String) req.getParameter("wodId"))).longValue(); // Create db connection for EJB workorderdetEJBean.connect(); // Delete the Item if (workorderdetEJBean.deleteProduct(wodId)) { req.setAttribute("errorMsg", "Product Key - " + wodId + " Deleted"); } else { req.setAttribute( "errorMsg", "Deletion Failed. Product Key - " + wodId + " is associated with amounts."); } // Release db connection for EJB workorderdetEJBean.release(); // Show the Item List screen listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } // Button action from JSP is to Save a Product. This includes Insertion // of New Product or Updation of an Existing Product. else if (sJSPAction.equals("save")) { boolean save = false; boolean newProd = false; // long qty=0; // Read the Billing System Id String formBsId = (String) req.getParameter("bs_id"); String bsysid = (String) req.getParameter("bsysid"); /* String trans_type = (String) req.getParameter("trans_type"); //String quantity = (String) req.getParameter("qty"); String quantity=""; if (!(req.getParameter("qty").equals(""))) { quantity=(String) req.getParameter("qty"); qty = (new Long(quantity).longValue()); } */ String prod_stat = (String) req.getParameter("prod_stat"); double nrcg_dscnt = (new Double((String) req.getParameter("NonRecurringDiscount"))).doubleValue(); double rcg_dscnt = (new Double((String) req.getParameter("RecurringDiscount"))).doubleValue(); String start_month = (String) req.getParameter("strt_month"); String start_day = (String) req.getParameter("strt_day"); String start_year = (String) req.getParameter("strt_year"); String end_month = (String) req.getParameter("end_month"); String end_day = (String) req.getParameter("end_day"); String end_year = (String) req.getParameter("end_year"); String start_date = start_month + "-" + start_day + "-" + start_year; String end_date = end_month + "-" + end_day + "-" + end_year; long wrkordrid = (new Long((String) session.getValue("WorkOrderId"))).longValue(); String for_editing = req.getParameter("for_editing"); String for_new = req.getParameter("for_new"); String formBkId = (String) req.getParameter("bk_id"); String formBKId = formBkId.substring(0, formBkId.indexOf("|")); String formBTN = formBkId.substring(formBkId.indexOf("|") + 1); billkeyId = (new Long(formBKId)).longValue(); try { bsId = (new Long((String) req.getParameter("bs_id"))).longValue(); } catch (Exception e) { USFEnv.getLog().writeDebug("Exception is " + e, this, null); } RHCCBlgKeys blgkeys = new RHCCBlgKeys(); if (for_editing.equals("editing")) { blgkeys.setRbkId(billkeyId); blgkeys.setRbkKeys(formBTN); blgkeys.setBsId(new Long(bsysid).longValue()); } if (for_new.equals("new")) { blgkeys.setRbkId(billkeyId); blgkeys.setRbkKeys(formBTN); blgkeys.setBsId(bsId); } int index = 0; WrkOrdrDets wod_obj = new WrkOrdrDets(); // wod_obj.setTxTyp(trans_type); // wod_obj.setQty(qty); wod_obj.setNonRcrgDscnt(nrcg_dscnt); wod_obj.setRcrgDscnt(rcg_dscnt); wod_obj.setRBKID(billkeyId); wod_obj.setWodStat(prod_stat); wod_obj.setWOID(wrkordrid); if (!(start_date.equals(""))) { strtDate = new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(start_date).getTime()); wod_obj.setStrtDat(strtDate); } // Else if the Start Date is null update the Item Object Date to // null else { wod_obj.setStrtDat(null); } // If Item Service End Date is not null read the date and update // the Item Object with the date if (!(end_date.equals(""))) { endDate = new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(end_date).getTime()); wod_obj.setEndDat(endDate); } // Else if the End Date is null update the Item Object Date to null else { wod_obj.setEndDat(null); } // Check if the Start Date is after the End Date or equals End Date if ((strtDate != null) && (endDate != null) && (strtDate.after(endDate))) { prodError = "Product Service Start Date is after Product Service End Date. \n"; index = 1; } else if ((strtDate != null) && (endDate != null) && (strtDate.equals(endDate))) { prodError = "Product Service Start Date equals Product Service End Date. \n"; } workorderdetEJBean.connect(); if (for_editing.equals("editing")) { long workorderdetID = (new Long((String) session.getValue("workorderdetid"))).longValue(); wod_obj.setWODID(workorderdetID); if (index == 0) { save = workorderdetEJBean.saveProduct(wod_obj); } if (save) { prodError = prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information updated"; req.setAttribute("error", prodError); } else { prodError = prodError + "<BR> Failed to update Product Information"; req.setAttribute("error", prodError); } } if (for_new.equals("new")) { if (index == 0) { int prodId = Integer.parseInt(req.getParameter("prod_Id")); wod_obj.setProd_id(prodId); save = workorderdetEJBean.saveProduct(wod_obj); } if (save) { prodError = prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information Saved"; req.setAttribute("error", prodError); } else { prodError = prodError + "<BR> Failed to Save Product Information"; req.setAttribute("error", prodError); } } workorderdetEJBean.release(); listProducts(wrkordrid, workorderdetEJBean, session, req, resp); } } // End of try block catch (Exception e) { if (workorderdetEJBean != null) { // calling bean release method try { workorderdetEJBean.release(); } catch (Exception ex) { USFEnv.getLog().writeCrit(" Exception in calling release() method ", this, e); } } String errorMsg = "Processing Exception in Items Servlet: "; USFEnv.getLog().writeCrit(errorMsg, this, e); errorJSP(req, resp, errorMsg); } // End of catch block } // end of doPost()
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ResultSet rs = null; try { // SET UP Context environment, to look for Data Pooling Resource Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB"); Connection dbcon = ds.getConnection(); // ########### SEARCH INPUT PARAMETERS, EXECUTE search // ##################################################### Vector<String> params = new Vector<String>(); params.add(request.getParameter("fname")); params.add(request.getParameter("lname")); params.add(request.getParameter("title")); params.add(request.getParameter("year")); params.add(request.getParameter("director")); List<Movie> movies = new ArrayList<Movie>(); movies = SQLServices.getMovies(params.toArray(new String[params.size()]), dbcon); // ########## SET DEFAULT SESSION() PARAMETERS #################################### request.getSession().removeAttribute("movies"); request.getSession().removeAttribute("linkedListMovies"); request.getSession().removeAttribute("hasPaged"); request.getSession().setAttribute("hasPaged", "no"); request.getSession().setAttribute("movies", movies); request.getSession().setAttribute("currentIndex", "0"); request.getSession().setAttribute("defaultN", "5"); // ########## IF MOVIES FROM SEARCH NON-EMPTY ########################################### List<String> fields = Movie.fieldNames(); int count = 1; if (!movies.isEmpty()) { request.setAttribute("movies", movies); for (String field : fields) { request.setAttribute("f" + count++, field); } request.getRequestDispatcher("../movieList.jsp").forward(request, response); } else { out.println("<html><head><title>error</title></head>"); out.println("<body><h1>could not find any movies, try your search again.</h1>"); out.println("<p> we are terribly sorry, please go back. </p>"); out.println("<table border>"); out.println("</table>"); } dbcon.close(); } catch (SQLException ex) { while (ex != null) { System.out.println("SQL Exception: " + ex.getMessage()); ex = ex.getNextException(); } } catch (java.lang.Exception ex) { out.println( "<html>" + "<head><title>" + "moviedb: error" + "</title></head>\n<body>" + "<p>SQL error in doGet: " + ex.getMessage() + "</p></body></html>"); return; } out.close(); }
private String processRequest( HttpServletRequest request, HttpServletResponse response, ConnectionPool conPool) throws Exception { // getting id parameters ParameterParser parameter = new ParameterParser(request); String bookID = parameter.getString(bookInterface.FIELD_ID, null); String sellerID = parameter.getString(bookInterface.FIELD_SELLERID, null); String message = parameter.getString(FIELD_MESSAGE, null); int codeID = parameter.getInt(bookInterface.FIELD_HIDDENID, 0); // get buyer's user object User user = (User) request.getSession().getAttribute(StringInterface.USERATTR); // security feauture: // if one of ids is missing or incorrect return false if (bookID == null || sellerID == null || codeID == 0 || bookID.length() != booksTable.ID_LENGTH || sellerID.length() != usersTable.ID_LENGTH || codeID != Math.abs(bookID.hashCode())) { return "We were unable to find the book you specified! Please make sure that the book id is correct."; } if (user.getID().equals(sellerID)) { return "You may not purchase an item from yourself!"; } // get connection Connection con = conPool.getConnection(); try { booksTable book = generalUtils.getBook(bookID, con); /*security feauture: *check seller id == passed hidden id *book != null */ if (book == null || !book.getSellerID().equals(sellerID)) { return "We were unable to find the book you specified! Please make sure that the book id is correct."; } usersTable sellerInfo = userUtils.getUserInfo(sellerID, con); usersTable buyerInfo = userUtils.getUserInfo(user.getID(), con); collegeTable college = getCollege(book.getCollegeID() + "", con); // if still here continue if (message == null) { request.setAttribute(ATTR_BOOK, book); request.setAttribute(ATTR_SELLER, sellerInfo); request.setAttribute(ATTR_BUYER, buyerInfo); request.setAttribute(ATTR_COLLEGE, college.getFull()); RequestDispatcher rd = getServletContext().getRequestDispatcher(PATH_BUY_CONFIRM); rd.include(request, response); return null; } else if (buy(book, user, con)) { // sending email to buyer request.setAttribute(mailInterface.USERATTR, buyerInfo.getUsername()); request.setAttribute(mailInterface.EMAILATTR, buyerInfo.getEmail()); request.setAttribute(mailInterface.BOOKATTR, book); request.setAttribute("book_id", bookID); request.setAttribute("seller_id", sellerID); RequestDispatcher rd = getServletContext().getRequestDispatcher(PATHBIDCONFIRMATION); rd.include(request, response); // sending email to seller request.setAttribute(ATTR_COLLEGE, college.getFull()); request.setAttribute(mailInterface.USERATTR, sellerInfo.getUsername()); request.setAttribute(mailInterface.EMAILATTR, sellerInfo.getEmail()); request.setAttribute(mailInterface.MESSAGEATTR, message); request.setAttribute(mailInterface.BOOKATTR, book); request.setAttribute(mailInterface.MOREATTR, buyerInfo); request.setAttribute("book_id", bookID); request.setAttribute("buyer_id", user.getID()); rd = getServletContext().getRequestDispatcher(PATHBOOKUPDATE); rd.include(request, response); // showing success message rd = getServletContext().getRequestDispatcher(PATH_BUY_SUCCESS); rd.include(request, response); return null; } else { throw new Exception("failed to process with buy"); } } catch (Exception e) { throw e; } finally { // recycle conPool.free(con); con = null; } }