`

JSF+A4J+Spring调用ORACLE存贮过程的拙作

阅读更多
      近一周写了一个简单的工具,本工具是通过Spring调用ORACLE的存贮过程,然后返回一个结果集合.用到的技术有JSF\AJAX4JSF\SPRING\facelet和进度条的控制\代码着色(codepress)等.其实现页面可以参考如下:


         部分代码如下:
    faces-config.xml
xml 代码
 
  1. xml version="1.0" encoding="UTF-8"?>  
  2. >  
  3.   
  4. <faces-config>  
  5.     <application>  
  6.         <variable-resolver>  
  7.             org.springframework.web.jsf.DelegatingVariableResolver  
  8.         <!---->variable-resolver>  
  9.         <view-handler>com.sun.facelets.FaceletViewHandler<!---->view-handler>  
  10.         <message-bundle>resources.messages<!---->message-bundle>  
  11.         <locale-config>  
  12.             <default-locale>zh<!---->default-locale>  
  13.             <supported-locale>en<!---->supported-locale>  
  14.         <!---->locale-config>  
  15.     <!---->application>  
  16.     <managed-bean>  
  17.         <managed-bean-name>tracePnrBean<!---->managed-bean-name>  
  18.         <managed-bean-class>  
  19.             com.travelsky.analyze.action.TracePnrBean  
  20.         <!---->managed-bean-class>  
  21.         <managed-bean-scope>request<!---->managed-bean-scope>  
  22.     <!---->managed-bean>  
  23.     <managed-bean>  
  24.         <managed-bean-name>tracePnrFltBean<!---->managed-bean-name>  
  25.         <managed-bean-class>  
  26.             com.travelsky.analyze.action.TracePnrFltBean  
  27.         <!---->managed-bean-class>  
  28.         <managed-bean-scope>request<!---->managed-bean-scope>  
  29.     <!---->managed-bean>  
  30.     <navigation-rule>  
  31.         <from-view-id>/login.xhtml<!---->from-view-id>  
  32.         <navigation-case>  
  33.             <from-outcome>Ok<!---->from-outcome>  
  34.             <to-view-id>/comein/AnalyzeMain.xhtml<!---->to-view-id>  
  35.             <redirect><!---->redirect>  
  36.         <!---->navigation-case>  
  37.         <navigation-case>  
  38.             <from-outcome>Ok2<!---->from-outcome>  
  39.             <to-view-id>/comein/AnalyzeTools.xhtml<!---->to-view-id>  
  40.         <!---->navigation-case>  
  41.     <!---->navigation-rule>  
  42.     <navigation-rule>  
  43.         <from-view-id>/comein/AnalyzeMain.xhtml<!---->from-view-id>  
  44.         <navigation-case>  
  45.             <from-outcome>Ok<!---->from-outcome>  
  46.             <to-view-id>/comein/AnalyzeMain.xhtml<!---->to-view-id>  
  47.         <!---->navigation-case>  
  48.     <!---->navigation-rule>  
  49.     <navigation-rule>  
  50.         <from-view-id>/comein/AnalyzeTools.xhtml<!---->from-view-id>  
  51.         <navigation-case>  
  52.             <from-outcome>Ok<!---->from-outcome>  
  53.             <to-view-id>/comein/AnalyzeTools.xhtml<!---->to-view-id>  
  54.         <!---->navigation-case>  
  55.     <!---->navigation-rule>  
  56. <!---->faces-config>  
TracePnrBean.java
java 代码
 
  1. package com.travelsky.analyze.action;  
  2.   
  3. import java.io.BufferedWriter;  
  4. import java.io.FileWriter;  
  5. import java.io.IOException;  
  6. import java.text.SimpleDateFormat;  
  7. import java.util.Date;  
  8. import java.util.HashMap;  
  9. import java.util.Iterator;  
  10. import java.util.Map;  
  11. import java.util.regex.Matcher;  
  12. import java.util.regex.Pattern;  
  13.   
  14. import javax.faces.context.FacesContext;  
  15.   
  16. import org.apache.commons.lang.StringUtils;  
  17. import org.springframework.jdbc.datasource.DriverManagerDataSource;  
  18.   
  19. import com.travelsky.analyze.serviceimpl.TrancePnrManagerImpl;  
  20.   
  21. public class TracePnrBean {  
  22.     private String PnrNo;  
  23.     private String TextPath;  
  24.   
  25.     private String InputPnrNo = "请输入PNR或REF号...";  
  26.   
  27.     public String getInputPnrNo() {  
  28.         return InputPnrNo;  
  29.     }  
  30.   
  31.     public void setInputPnrNo(String inputPnrNo) {  
  32.         InputPnrNo = inputPnrNo;  
  33.     }  
  34.   
  35.     public String getPnrNo() {  
  36.         return RunTracePnr();  
  37.     }  
  38.   
  39.     public void setPnrNo(String pnrNo) {  
  40.         PnrNo = RunTracePnr();  
  41.     }  
  42.     public String getTextPath() {  
  43.         return this.OutText(RunTracePnr());  
  44.     }  
  45.   
  46.     public void setTextPath(String textPath) {  
  47.         TextPath = textPath;  
  48.     }  
  49.     public String RunTracePnr() {  
  50.         String TracePnrStr = "\n";  
  51.         DriverManagerDataSource ds = new DriverManagerDataSource();  
  52.         ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");  
  53.         ds.setUrl("jdbc:oracle:thin:@10.6.168.134:1521:dss9i");  
  54.         ds.setUsername("dss_pdata");  
  55.         ds.setPassword("dss_pdata");  
  56.         TrancePnrManagerImpl sp = new TrancePnrManagerImpl(ds, "tracepnr");  
  57.         sp.setParameter("pnr_nbr_in", java.sql.Types.VARCHAR);  
  58.         sp.setOutParameter("print_pnr", oracle.jdbc.OracleTypes.VARCHAR);  
  59.         sp.compile();  
  60.         TrancePnrManagerImpl sp2 = new TrancePnrManagerImpl(ds, "reftracepnr");  
  61.         sp2.setParameter("pnr_ref_in", java.sql.Types.VARCHAR);  
  62.         sp2.setOutParameter("print_pnr", oracle.jdbc.OracleTypes.VARCHAR);  
  63.         sp2.setOutParameter("print_pnr_sfx1", oracle.jdbc.OracleTypes.VARCHAR);  
  64.         sp2.compile();  
  65.         /** 
  66.          * 对输入的数据进行一次处理 
  67.          */  
  68.         StringUtils t1 = new StringUtils();  
  69.         String InputPnrNoList = this.getInputPnrNo();  
  70.         InputPnrNoList = t1.deleteWhitespace(InputPnrNoList);  
  71.         String[] SInputPnrNo = t1.split(InputPnrNoList, ",");  
  72.         for (int j = 0; j < SInputPnrNo.length; j++) {  
  73.             String PnrRef = SInputPnrNo[j];  
  74.             // 传入输入参数值  
  75.             if (PnrRef.length() == 9) {  
  76.                 Map in = new HashMap(1);  
  77.                 in.put("pnr_nbr_in", PnrRef);  
  78.                 sp.SetInParam(in);  
  79.   
  80.                 // 执行存储过程  
  81.                 Map m = sp.execute();  
  82.                 Iterator i = m.keySet().iterator();  
  83.                 while (i.hasNext()) {  
  84.                     String key = i.next().toString();  
  85.                     TracePnrStr += m.get(key);                    
  86.                 }  
  87.             }  
  88.             if (PnrRef.length() == 5) {  
  89.                 Map in = new HashMap(1);  
  90.                 in.put("pnr_ref_in", PnrRef);  
  91.                 sp2.SetInParam(in);  
  92.   
  93.                 // 执行存储过程  
  94.                 Map m = sp2.execute();  
  95.   
  96.                 // Map m = sp.set.get(0);// ReultSet的第一条记录  
  97.                 // set定义为SpringStoredProcedure的属性用于接收回调时的数据  
  98.                 // 如果有多个输出参数,应该在每个输出参数的回调方法中生成该输出  
  99.                 // 参数对应的ArrayList,然后加到一个成员变量的数据结构中。  
  100.                 Iterator i = m.keySet().iterator();  
  101.                 while (i.hasNext()) {  
  102.                     String key = i.next().toString();  
  103.                     TracePnrStr += m.get(key);  
  104.                 }  
  105.             }  
  106.             TracePnrStr = t1.replace(TracePnrStr, "<newline>"</newline>"\n");  
  107.             TracePnrStr = TracePnrStr + "\n \n";// 最后一个加换行  
  108.         }  
  109.         //this.OutText(TracePnrStr);  
  110.         return TracePnrStr;  
  111.     }  
  112.   
  113.       
  114.     public String Finish(){  
  115.         return "Ok";  
  116.     }  
  117.   
  118.     public String OutText(String TracePnrStr) {       
  119.         SimpleDateFormat myFmt=new SimpleDateFormat("yyyyMMddHHmmss");        
  120.         String PathText = myFmt.format(new Date());  
  121.         try {  
  122.             BufferedWriter out = new BufferedWriter(new FileWriter(  
  123.                     "D:\\tomcat5523\\webapps\\analyze\\doc\\pnr"+PathText+".txt"true));// 主要就是这个true  
  124.             //out.newLine();// 如果不另起一行的话就注释掉  
  125.             out.write(TracePnrStr);  
  126.             out.close();  
  127.         } catch (IOException e) {  
  128.             e.printStackTrace();  
  129.         }  
  130.         return "pnr"+PathText+".txt";  
  131.     }  
  132.   
  133.   
  134.   
  135. }  

分享到:
评论
2 楼 heweiya 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>帮助你使用模糊的进度条.
如果看官有什么疑问和见意,可以斧正.
呵呵.
1 楼 heweiya 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>

相关推荐

    JSF+Spring+Ibatis示例

    JSF+Spring+Ibatis示例,对学习JAVA企业应用开发有巨大的帮助!

    Struts+JSF+filter+Myfaces+A4j+Spring+hibernate+Mysql整合一个项目

    "Struts+JSF+filter+Myfaces+A4j+Spring+hibernate+Mysql整合一个项目"就是一个典型的例子,它涉及到前端展现、业务逻辑处理、数据持久化以及数据库管理等多个层面。以下是对这些技术的详细说明: **Struts**:...

    jsf+spring+hibernate

    【JSF+Spring+Hibernate整合开发】 JSF (JavaServer Faces)、Spring 和 Hibernate 是 Java 开发中的三大核心技术,常用于构建企业级的 Web 应用程序。它们各自扮演着不同的角色,共同构建了一个强大的后端架构。 1...

    JSF+Spring+Hibernate小例子

    **JSF+Spring+Hibernate整合应用详解** 在Java Web开发中,JSF(JavaServer Faces)、Spring和Hibernate是三个常用的技术栈,它们分别负责视图层、业务逻辑层和服务数据持久化层。这个"JSF+Spring+Hibernate小例子...

    jsf+hibernate+spring集成案例

    在IT领域,JavaScript Server Faces(JSF)、Hibernate和Spring是三个非常重要的技术,它们分别用于构建用户界面、处理持久化和实现应用框架。本集成案例将深入探讨这三者的结合,帮助开发者理解如何在实际项目中...

    JSF+Spring+Hibernate(框架整合)详细过程

    通过Managed Bean,JSF可以与Spring的Service层进行通信,传递数据并调用业务方法。 7. **事务管理**:Spring提供了强大的事务管理功能,可以配置在Service层的方法上,确保数据操作的原子性、一致性、隔离性和持久...

    jsf+spring+hibernate实例

    在整合JSF、Spring和Hibernate的过程中,首先,需要配置Spring的ApplicationContext,声明Bean定义,包括JSF Managed Beans、Service层接口及其实现、Hibernate SessionFactory等。接着,JSF页面通过Managed Bean...

    拍卖系统jsf+ejb+jpa

    5. **集成**:JSF、EJB和JPA通过Java EE容器(如Tomcat、WildFly)进行统一管理,它们之间的通信遵循Java EE规范,例如JSF调用EJB服务,EJB通过JPA操作数据库。 这样的整合方式提供了完整的MVC(Model-View-...

    JSF+Spring+Hibernate jar lib

    JSF+Spring+Hibernate jar文件压缩包,hibernate最小配置,Spring 2.0 jar, richfaces

    ajax+jsf+spring+hibernate

    **Ajax、JSF、Spring和Hibernate是四种在Java Web开发中广泛应用的技术,它们共同构建了高效、灵活且功能强大的Web应用程序。** **Ajax(Asynchronous JavaScript and XML)** 是一种在无需重新加载整个网页的情况...

    jsf+spring+hibernate架构的网上商店

    3. **服务层**:Spring 作为业务逻辑的服务层,封装了与数据库的交互,提供了接口供JSF调用。 4. **安全控制**:Spring Security 可以用来实现用户认证和授权,保护系统资源。 ### Hibernate ORM Hibernate 是一个...

    jsf+spring 实例

    - 使用JSF页面调用Spring服务:在JSF的XHTML页面中,通过EL表达式直接引用Spring Bean的方法。 **5. JBoss服务器** JBoss是基于Java EE的开源应用服务器,它支持JSF和Spring的部署。开发者需要将配置好的Web应用...

    JSF+Spring+Hibernate的实例讲解.doc

    在 JCatalog 示例中,Spring 可能用于实现业务服务接口,提供对 Hibernate DAO 的封装,而 JSF 的 Managed Beans 作为视图与控制器的结合,负责处理用户请求并调用 Spring 服务。此外,安全控制也应纳入设计考虑,如...

    基于JSF+EJB3+JPA的竞价拍卖系统

    JSF的生命周期包括六步:恢复视图、应用请求值、处理验证、更新模型值、调用应用逻辑和渲染响应,确保了数据的正确流动和页面的动态更新。 **2. Enterprise JavaBeans 3 (EJB3)** EJB3 是Java EE平台的一部分,...

    jsf+spring+servlet的demo

    总的来说,这个"jsf+spring+servlet的demo"是一个综合性的Web应用实例,它演示了如何利用JSF构建用户界面,Spring处理业务逻辑,以及Servlet协调请求处理。开发者可以从中学习到如何集成这三个技术,理解它们在实际...

    jsf+spring2.5+jpa(hibernate)的jar包

    这是jsf+spring2.5+jpa(hibernate)的jar包,很多人为了jsj环境而配置半天,在此提供jar包共享。注:除了ajax4jsf和tomahawk-1.1.3.jar,因为csdn只让我上传20mb,大家自己可以下一下自己试试。

    经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第3章

    经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第3章 其他部分详见我的上传列表 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则包含...

    JSF+HIbernate+Spring结合

    ### JSF + Hibernate + Spring 的整合实践 #### 一、技术背景与介绍 在现代Web开发领域中,Java Server Faces (JSF)、Hibernate以及Spring是三个非常重要的框架和技术。这三个技术结合使用可以构建出高性能、高...

Global site tag (gtag.js) - Google Analytics