浏览 3666 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-08-17
部分代码如下: faces-config.xml xml 代码
java 代码
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-08-17
接上面:
TracePnrFltBean.java package com.travelsky.analyze.action; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.springframework.jdbc.datasource.DriverManagerDataSource; import com.travelsky.analyze.hibernate.model.InputCondiction; import com.travelsky.analyze.serviceimpl.TrancePnrManagerImpl; public class TracePnrFltBean { private String PnrNo = ""; private InputCondiction condition = new InputCondiction(); private String TextPath = ""; public InputCondiction getCondition() { if (condition.getSelectType() == null) { condition.setSelectType("1"); } return condition; } public void setCondition(InputCondiction condition) { this.condition = condition; } public String getTextPath() { return this.OutText(RunTracePnrFlt()); } public String getPnrNo() { return RunTracePnrFlt(); } public void setPnrNo(String pnrNo) { PnrNo = pnrNo; } public String RunTracePnrFlt() { String TracePnrStr = "\n"; /** * 对输入的数据进行一次处理 */ StringUtils t1 = new StringUtils(); String InputCarrCd = condition.getCarrCd(); InputCarrCd = t1.deleteWhitespace(InputCarrCd);// 航空公司 if (InputCarrCd == null) { return TracePnrStr; } String InputFltNbr = condition.getFltNbr(); InputFltNbr = t1.deleteWhitespace(InputFltNbr);// 航班号 String InputFltNbrSfx = condition.getFltNbrSfx(); InputFltNbrSfx = t1.deleteWhitespace(InputFltNbrSfx);// 航班号后缀 String InputDptDtLcl = condition.getDptDtLcl(); InputDptDtLcl = t1.deleteWhitespace(InputDptDtLcl);// 起飞日期 String InputIdNbr = condition.getIdNbr(); InputIdNbr = t1.deleteWhitespace(InputIdNbr);// 有效证件号 String InputCnName = condition.getCnName(); InputCnName = t1.deleteWhitespace(InputCnName); String InputEnFirstName = condition.getEnFirstName(); InputEnFirstName = t1.deleteWhitespace(InputEnFirstName); String InputEnLastName = condition.getEnLastName(); InputEnLastName = t1.deleteWhitespace(InputEnLastName); String InputSelectType = condition.getSelectType(); InputSelectType = t1.deleteWhitespace(InputSelectType); DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); ds.setUrl("jdbc:oracle:thin:@10.6.168.134:1521:dss9i"); ds.setUsername("dss_pdata"); ds.setPassword("dss_pdata"); if (InputSelectType.equals("1")) { // 执行有效证件号码的程序 TrancePnrManagerImpl sp1 = new TrancePnrManagerImpl(ds, "tracepnr_flt_id_nbr"); sp1.setParameter("carr_cd_in", java.sql.Types.VARCHAR); sp1.setParameter("flt_nbr_in", java.sql.Types.VARCHAR); sp1.setParameter("flt_nbr_sfx_in", java.sql.Types.VARCHAR); sp1.setParameter("dpt_dt_lcl_in", java.sql.Types.VARCHAR); sp1.setParameter("id_nbr_in", java.sql.Types.VARCHAR); sp1.setOutParameter("print_pnr", oracle.jdbc.OracleTypes.VARCHAR); sp1.compile(); Map in = new HashMap(1); in.put("carr_cd_in", InputCarrCd); in.put("flt_nbr_in", InputFltNbr); in.put("flt_nbr_sfx_in", InputFltNbrSfx); in.put("dpt_dt_lcl_in", InputDptDtLcl); in.put("id_nbr_in", InputIdNbr); sp1.SetInParam(in); // 执行存储过程 Map m = sp1.execute(); Iterator i = m.keySet().iterator(); while (i.hasNext()) { String key = i.next().toString(); TracePnrStr += m.get(key); TracePnrStr = t1.replace(TracePnrStr, "<newline>", "\n"); TracePnrStr = TracePnrStr + "\n \n";// 最后一个加换行 } return TracePnrStr; } if (InputSelectType.equals("2")) { // 执行中文姓名的程序 TrancePnrManagerImpl sp2 = new TrancePnrManagerImpl(ds, "tracepnr_flt_cn_nm"); sp2.setParameter("carr_cd_in", java.sql.Types.VARCHAR); sp2.setParameter("flt_nbr_in", java.sql.Types.VARCHAR); sp2.setParameter("flt_nbr_sfx_in", java.sql.Types.VARCHAR); sp2.setParameter("dpt_dt_lcl_in", java.sql.Types.VARCHAR); sp2.setParameter("pax_cn_nm_in", java.sql.Types.VARCHAR); sp2.setOutParameter("print_pnr", oracle.jdbc.OracleTypes.VARCHAR); sp2.compile(); Map in = new HashMap(1); in.put("carr_cd_in", InputCarrCd); in.put("flt_nbr_in", InputFltNbr); in.put("flt_nbr_sfx_in", InputFltNbrSfx); in.put("dpt_dt_lcl_in", InputDptDtLcl); in.put("pax_cn_nm_in", InputCnName); sp2.SetInParam(in); // 执行存储过程 Map m = sp2.execute(); Iterator i = m.keySet().iterator(); while (i.hasNext()) { String key = i.next().toString(); TracePnrStr += m.get(key); TracePnrStr = t1.replace(TracePnrStr, "<newline>", "\n"); TracePnrStr = TracePnrStr + "\n \n";// 最后一个加换行 } return TracePnrStr; } if (InputSelectType.equals("3")) { // 执行英文姓名的程序 TrancePnrManagerImpl sp3 = new TrancePnrManagerImpl(ds, "tracepnr_flt_en_nm"); sp3.setParameter("carr_cd_in", java.sql.Types.VARCHAR); sp3.setParameter("flt_nbr_in", java.sql.Types.VARCHAR); sp3.setParameter("flt_nbr_sfx_in", java.sql.Types.VARCHAR); sp3.setParameter("dpt_dt_lcl_in", java.sql.Types.VARCHAR); sp3.setParameter("fst_nm_in", java.sql.Types.VARCHAR); sp3.setParameter("lst_nm_in", java.sql.Types.VARCHAR); sp3.setOutParameter("print_pnr", oracle.jdbc.OracleTypes.VARCHAR); sp3.compile(); Map in = new HashMap(1); in.put("carr_cd_in", InputCarrCd); in.put("flt_nbr_in", InputFltNbr); in.put("flt_nbr_sfx_in", InputFltNbrSfx); in.put("dpt_dt_lcl_in", InputDptDtLcl); in.put("fst_nm_in", InputEnFirstName); in.put("lst_nm_in", InputEnLastName); sp3.SetInParam(in); // 执行存储过程 Map m = sp3.execute(); Iterator i = m.keySet().iterator(); while (i.hasNext()) { String key = i.next().toString(); TracePnrStr += m.get(key); TracePnrStr = t1.replace(TracePnrStr, "<newline>", "\n"); TracePnrStr = TracePnrStr + "\n \n";// 最后一个加换行 } return TracePnrStr; } return TracePnrStr; } public String Finish() { // 空转 return "Ok"; } public String OutText(String TracePnrStr) { SimpleDateFormat myFmt = new SimpleDateFormat("yyyyMMddHHmmss"); String PathText = myFmt.format(new Date()); try { BufferedWriter out = new BufferedWriter(new FileWriter( "D:\\tomcat5523\\webapps\\analyze\\doc\\flt" + PathText + ".txt", true));// 主要就是这个true // out.newLine();// 如果不另起一行的话就注释掉 out.write(TracePnrStr); out.close(); } catch (IOException e) { e.printStackTrace(); } return "flt" + PathText + ".txt"; } } TrancePnrManagerImpl.java package com.travelsky.analyze.serviceimpl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import javax.sql.DataSource; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapperResultReader; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.object.StoredProcedure; import com.travelsky.analyze.service.TrancePnrManager; public class TrancePnrManagerImpl extends StoredProcedure implements TrancePnrManager { public ArrayList<HashMap> set = new ArrayList<HashMap>(); // 声明一个用于接收结果集的数据结构,其中的元素为row,用map存放 private Map inParam;// 输入参数 private RowMapper rm = new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return null;// 不用从存储过程本身获取结果 } }; private RowMapperResultReader callback = new RowMapperResultReader(rm) { public void processRow(ResultSet rs) // 回调处理 throws SQLException { int count = rs.getMetaData().getColumnCount(); String[] header = new String[count]; for (int i = 0; i < count; i++) header[i] = rs.getMetaData().getColumnName(i + 1); while (rs.next()) { HashMap<String, String> row = new HashMap(count + 7); for (int i = 0; i < count; i++) row.put(header[i], rs.getString(i + 1)); set.add(row); } } }; // RowMapperResultReader作为输出参数的回调句柄 public TrancePnrManagerImpl(DataSource ds, String SQL) { setDataSource(ds); setSql(SQL); } public void setOutParameter(String column, int type) { declareParameter(new SqlOutParameter(column, type, callback)); // 利用回调句柄注册输出参数 } public void setParameter(String column, int type) { declareParameter(new SqlParameter(column, type)); } public void SetInParam(Map inParam) { this.inParam = inParam; } public Map execute() { compile(); return execute(this.inParam); } } 两个页面文件:AnalyzeMain.xhtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:rick="http://richfaces.ajax4jsf.org/rich" xmlns:a4j="https://ajax4jsf.dev.java.net/ajax" lang="gb2312"> <head> <title>Trace PNR</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <script src="../codepress/codepress.js" type="text/javascript"></script> <link href="../css/style.css" rel="stylesheet" type="text/css" /> </head> <body style="margin:0; padding:0;"> <center> <p align="right"> <a href="../login.xhtml"><font color="blue">注销</font> </a> </p> <h2 style="margin-top:5px"> <strong><font size="14" color="blue">Trace PNR</font> </strong> </h2> <div id="tabs1"> <ul> <!-- CSS Tabs --> <li> <a id="current" href="AnalyzeMain.xhtml"><span>查询PNR记录编号</span> </a> </li> <li> <a id="Pro2" href="AnalyzeTools.xhtml"><span>组合条件查询</span> </a> </li> </ul> </div> <f:view> <h:form id="SoGou"> <a4j:region id="stat1"> <h:inputTextarea value="#{tracePnrBean.inputPnrNo}" id="PnrNo" cols="50" rows="4" onclick="Inint();" title="请输入PNR号或者REF号,以逗号分隔!"> </h:inputTextarea> <p style="margin: 0px;"> <a4j:commandButton action="#{tracePnrBean.Finish}" id="Sou1" value="查询" reRender="SoGou:myCpWindow" oncomplete="FinistIt()" onclick="BeginIt();"> </a4j:commandButton> </p> <a4j:status for="stat1"> <f:facet name="start"> <h:graphicImage value="../images/progressbar_green.gif" /> </f:facet> </a4j:status> <div id="Out"> <font color="blue">导出为:</font><a href="../doc/#{tracePnrBean.textPath}" title="导出TXT文件" target="_blank">[TXT]</a>[XML] </div> <a4j:outputPanel id="myCpWindow" ajaxRendered="true" layout="inline"> <div id="Result"> <h:inputTextarea id="sws" value="#{tracePnrBean.pnrNo}" cols="56" rows="16" styleClass="codepress sql linenumbers-on" immediate="true"></h:inputTextarea> </div> </a4j:outputPanel> </a4j:region> </h:form> <h:outputLabel> <font color="blue">中航信版权所有 @2007 Travesky</font> </h:outputLabel> </f:view> </center> <script type="text/javascript"> function Inint(){ var InputNo = document.getElementsByName("SoGou:PnrNo")[0]; if (InputNo.value=="请输入PNR或REF号..."){ InputNo.value=""; } } function BeginIt(){ var Sou1 = document.getElementsByName("SoGou:Sou1")[0]; Sou1.disabled="true"; } function FinistIt(){ var Sou1 = document.getElementsByName("SoGou:Sou1")[0]; alert("计算完成,请查看结果!"); Sou1.disabled="false"; } </script> </body> </html> |
|
返回顶楼 | |
发表时间:2007-08-17
接上面:
两个页面文件AnalyzeTools.xhtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="https://ajax4jsf.dev.java.net/ajax" lang="gb2312"> <head> <title>Trace PNR</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <script src="../codepress/codepress.js" type="text/javascript"></script> <link href="../css/style.css" rel="stylesheet" type="text/css" /> </head> <body style="margin:0; padding:0;" onload="ChangeType(#{tracePnrFltBean.condition.selectType})"> <center> <p align="right"> <a href="../login.xhtml"><font color="blue">注销</font> </a> </p> <h2 style="margin-top:5px"> <strong><font size="14" color="blue">Trace PNR</font> </strong> </h2> <div id="tabs1"> <ul> <!-- CSS Tabs --> <li> <a id="current" href="AnalyzeMain.xhtml"><span>查询PNR记录编号</span> </a> </li> <li> <a id="Pro2" href="AnalyzeTools.xhtml"><span>组合条件查询</span> </a> </li> </ul> </div> <f:view> <h:form id="SoGou" onsubmit="return BeginIt();"> <a4j:region id="stat1"> <table align="center"> <tr> <td> 航空公司代码 </td> <td> <h:inputText title="航空公司代码" value="#{tracePnrFltBean.condition.carrCd}" id="carrCd" /> </td> <td> 起飞日期 </td> <td> <h:inputText title="起飞日期,输入格式为:yyyymmdd" value="#{tracePnrFltBean.condition.dptDtLcl}" id="dptDtLcl" maxlength="8"> </h:inputText> </td> </tr> <tr> <td> 航班号 </td> <td> <h:inputText title="航班号" value="#{tracePnrFltBean.condition.fltNbr}" id="fltNb" /> </td> <td> 航班号后缀 </td> <td> <h:inputText title="航班号后缀" value="#{tracePnrFltBean.condition.fltNbrSfx}" id="fltNbrSfx" /> </td> </tr> <tr> <td> 查询方式 </td> <td colspan="3" align="left"> <h:selectOneRadio title="查询方式" id="selectType" value="#{tracePnrFltBean.condition.selectType}" onclick="ChangeType(this.value);"> <f:selectItem itemValue="1" itemLabel="有效证件号" /> <f:selectItem itemValue="2" itemLabel="中文姓名" /> <f:selectItem itemValue="3" itemLabel="英文姓名" /> </h:selectOneRadio> </td> </tr> </table> <a4j:outputPanel id="ById"> <table align="center"> <tr> <td width="15%"> 有效证件号 </td> <td> <h:inputText title="有效证件号" value="#{tracePnrFltBean.condition.idNbr}" id="idNbr" /> </td> <td width="25%"> </td> <td width="25%"> </td> </tr> </table> </a4j:outputPanel> <a4j:outputPanel id="ByCnName" style="display:none;"> <table align="center"> <tr> <td> 旅客中文姓名 </td> <td> <h:inputText title="旅客中文姓名" value="#{tracePnrFltBean.condition.cnName}" id="cnName" /> </td> <td width="24%"> </td> <td width="25%"> </td> </tr> </table> </a4j:outputPanel> <a4j:outputPanel id="ByEnName" style="display:none;"> <table align="center"> <tr> <td> First Name </td> <td> <h:inputText title="First Name" value="#{tracePnrFltBean.condition.enFirstName}" id="enFirstName" /> </td> <td> Last Name </td> <td> <h:inputText title="Last Name" value="#{tracePnrFltBean.condition.enLastName}" id="enLastName" /> </td> </tr> </table> </a4j:outputPanel> <p style="margin: 0px;"> <a4j:commandButton action="#{tracePnrFltBean.Finish}" id="Sou1" value="查询" reRender="SoGou:myCpWindow" oncomplete="FinistIt()" type="submit"> </a4j:commandButton> </p> <a4j:status for="stat1"> <f:facet name="start"> <h:graphicImage value="../images/progressbar_green.gif" /> </f:facet> </a4j:status> <div id="Out"> <font color="blue">导出为:</font><a href="../doc/#{tracePnrFltBean.textPath}" title="导出TXT文件" target="_blank">[TXT]</a>[XML] </div> <a4j:outputPanel id="myCpWindow" ajaxRendered="true" layout="inline"> <div id="Result"> <h:inputTextarea id="sws" value="#{tracePnrFltBean.pnrNo}" cols="56" rows="16" styleClass="codepress sql linenumbers-on" immediate="true"></h:inputTextarea> </div> </a4j:outputPanel> </a4j:region> </h:form> <h:outputLabel> <font color="blue">中航信版权所有 @2007 Travesky</font> </h:outputLabel> </f:view> </center> <script type="text/javascript"> function BeginIt(){ //算了,组件太机械化了,还是小米加步枪吧. var errorinfo = ""; var isFocus = true; var carrCd = document.getElementsByName("SoGou:carrCd")[0]; var dptDtLcl = document.getElementsByName("SoGou:dptDtLcl")[0]; var fltNb = document.getElementsByName("SoGou:fltNb")[0]; var fltNbrSfx = document.getElementsByName("SoGou:fltNbrSfx")[0]; var selectType = document.getElementsByName("SoGou:selectType"); var idNbr = document.getElementsByName("SoGou:idNbr")[0]; var cnName = document.getElementsByName("SoGou:cnName")[0]; var enFirstName = document.getElementsByName("SoGou:enFirstName")[0]; var enLastName = document.getElementsByName("SoGou:enLastName")[0]; var returnSelect=""; if (carrCd.value.trim() == ""){ errorinfo += "航空公司为必填项,请输入!\n"; if(isFocus){ carrCd.focus(); isFocus = false; } } if (dptDtLcl.value.trim() == ""){ errorinfo += "起飞日期为必填项,请输入!\n"; if(isFocus){ dptDtLcl.focus(); isFocus = false; } }else{ var patrn=/^(\d{4})(\/|)(\d{1,2})(\/|)(\d{1,2})$/;; if (!patrn.exec(dptDtLcl.value.trim())){ errorinfo += "起飞日期格式不正确,请输入格式为YYYYMMDD!\n"; if(isFocus){ dptDtLcl.focus(); isFocus = false; } } } if (fltNb.value.trim() == ""){ errorinfo += "航班号为必填项,请输入!\n"; if(isFocus){ fltNb.focus(); isFocus = false; } } //不知道为什么不支持selectType.length if (selectType[1].checked){ returnSelect=selectType[1].value; } if (selectType[2].checked){ returnSelect=selectType[2].value; } if (selectType[3].checked){ returnSelect=selectType[3].value; } if (returnSelect == 1){ if (idNbr.value.trim() == ""){ errorinfo += "有效证件号为必填项,请输入!\n"; if(isFocus){ idNbr.focus(); isFocus = false; } } } if (returnSelect == 2){ if (cnName.value.trim() == ""){ errorinfo += "旅客中文姓名为必填项,请输入!\n"; if(isFocus){ cnName.focus(); isFocus = false; } } } if (returnSelect == 3){ if (enFirstName.value.trim() == ""){ errorinfo += "First Name为必填项,请输入!\n"; if(isFocus){ enFirstName.focus(); isFocus = false; } } if (enLastName.value.trim() == ""){ errorinfo += "Last Name为必填项,请输入!\n"; if(isFocus){ enLastName.focus(); isFocus = false; } } } if (errorinfo != ""){ alert(errorinfo); return false; } var Sou1 = document.getElementsByName("SoGou:Sou1")[0]; Sou1.disabled="true"; } String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); } function ChangeType(Pid){ var byid = document.getElementsByName("SoGou:ById")[0]; var byCnName = document.getElementsByName("SoGou:ByCnName")[0]; var byEnName = document.getElementsByName("SoGou:ByEnName")[0]; if (Pid == 1){ byCnName.style.display="none"; byEnName.style.display="none"; byid.style.display="block"; } if (Pid == 2){ byid.style.display="none"; byEnName.style.display="none"; byCnName.style.display="block"; } if (Pid == 3){ byid.style.display="none"; byCnName.style.display="none"; byEnName.style.display="block"; } } function FinistIt(){ var Sou1 = document.getElementsByName("SoGou:Sou1")[0]; alert("计算完成,请查看结果!"); Sou1.disabled="false"; } </script> </body> </html> 注:主要使用JSF做展现,使用AJAX4JSF做辅助,因为是刚刚学习ajax4jsf所以做法还很牵强.但是有两个知识点可能帮助你拓展一些思路: 1\codepress,帮助你着色. 2\ajax4jsf的<a4j:status>帮助你使用模糊的进度条. 如果看官有什么疑问和见意,可以斧正. 呵呵. |
|
返回顶楼 | |