<%@ page import="com.syxa.https.Search"%>
<%@ page import="com.syxa.https.dto.HcMessageDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="/DemoHttpClient/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
function yj(data,carrier,flightNumber,depAirport,depTime,arrAirport,arrTime,stopCities,codeShare,cabin,aircraftCode){
var oID=document.getElementById("cid").value;/* 拿到A_form中的id值 */
var oHID=document.getElementById("id"); /* 拿到B_form中的隐藏域对象 */
oHID.value=oID; /* 为隐藏域对象的value赋值 */
var n=document.getElementById("tripTpye").value;
var nt=document.getElementById("tripT");
nt.value=n;
var A=document.getElementById("adultNumber").value;
var AN=document.getElementById("adultN");
AN.value=A;
var C=document.getElementById("childNumber").value;
var CN=document.getElementById("childN");
CN.value=C;
$.ajax({
type : "POST",
url : "demo.do?type=verify",
data : {
"id":$("#id").val(),
"tripT":$("#tripT").val(),
"adultN":$("#adultN").val(),
"childN":$("#childN").val(),
"data":data,
"carrier":carrier,
"flightNumber":flightNumber,
"depAirport":depAirport,
"depTime":depTime,
"arrAirport":arrAirport,
"arrTime":arrTime,
"stopCities":stopCities,
"codeShare":codeShare,
"cabin":cabin,
"aircraftCode":aircraftCode
},
async : false,
dataType : "json",
success : function(data) {
alert(data);
/* window.open(DemoHttpClient/jsp/seand.jsp); */
if (data) {//根据返回值进行跳转
var dataValue = "/DemoHttpClient/jsp/seand.jsp?data"+data;
window.location.replace(dataValue);
//window.location.href = "/DemoHttpClient/jsp/seand.jsp?data"+data;
}
},
error:function(message){
alert("ajax参数错误!");
}
});
}
</script>
</head>
<body>
<div class="" align="center">
<div class="row">
<div class="">
<div class="">
<form action="demo.do?type=query" id="tf" method="post" onsubmit="SomeJavaScriptCode">
<table class="" >
<tr>
<th>销售渠道:</th>
<td>
<select name="cid" id="cid">
<!-- <option value="ctrip20180507">携程-正航-ctrip</option>
<option value="qunar20180511">去哪儿-正航-qunar</option>
<option value="testcid001">testctrip-正航test-ctrip</option>
<option value="ali20180525hf">阿里航服-正航-ali</option>
<option value="ali20180525jp">阿里金牌-正航-ali</option>
<option value="ali20180525js">阿里极速-正航-ali</option>
<option value="testcid002">testali-正航test-ali</option>
<option value="test20180711tuniu">途牛-途牛test-tuniu</option> -->
<option value="testcid003">testqunar-正航test-qunar</option>
</select>
</td>
<th>航程类型:</th>
<td>
<select name="tripTpye" id="tripTpye">
<option value="1">单程</option>
<option value="roundTrip">往返</option>
</select>
</td>
<th>成人</th>
<td>
<select name="adultNum" id="adultNumber">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
<th>儿童</th>
<td>
<select name="childNum" id="childNumber">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
<th>出发地:</th>
<td><input name="fromCity" value="HKG" id="fromCity" type="test"></td>
<th>目的地:</th>
<td><input name="toCity" value="XMN" id="toCity" type="test"></td>
<!-- <th>航司:</th>
<td><input name="carrier" id="carrier" value="" type="text" ></td> -->
</tr>
<tr>
<th>出发日期:</th>
<td><input name="fromDate" value="20180901" /></td>
<th>返回日期:</th>
<td><input name="retDate" value="" /></td>
<!-- <th>航班号:</th>
<td><input name="flightnumbers" value="" id="flightnumbers" type="text" class="form-control input-sm"></td> -->
</tr>
</table>
<div align="center">
<!-- <input type="button" class="btn btn-primary" onclick="search()" value="查询"> -->
<input type="submit" value="查询">
<input type="reset" value="取消">
</div>
</form>
<br>
</div>
</div>
</div>
</div>
<div class="" align="center" >
<div class="row">
<div class="col-sm-12">
<div class="ibox ">
<div class="ibox-title"></div>
<div class="ibox-content">
<div class="zbss-table-wrapper table-responsive">
<form action="demo.do?type=verify" method="post" id="tf" class="formdata">
<table class="table table-striped table-hover table-condense" border="1" cellspacing="0">
<thead>
<tr>
<th>成人单价</th>
<th>成人税费</th>
<th>成人税费类型</th>
<th>报价类型</th>
<th>儿童单价</th>
<th>儿童税费</th>
<th>儿童税费类型</th>
<th>data</th>
<th>去程航段</th>
<th>乘客国籍</th>
<th>乘客国籍类型</th>
<th>报价类型</th>
<th>回程航段</th>
<th>退改签信息</th>
<th>适用乘客年龄</th>
<th>报销凭证类型</th>
<th>出票速度</th>
<th style="display: none;">销售渠道</th>
<th style="display: none;">行程类型</th>
<th style="display: none;">成人乘机总人 数</th>
<th style="display: none;">儿童乘机总人 数</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="list" items="${requestScope.tlist}">
<tr>
<td>${list.adultPrice }</td>
<td>${list.adultTax }</td>
<td>${list.adultTaxType }</td>
<td>${list.applyType }</td>
<td>${list.childPrice }</td>
<td>${list.childTax }</td>
<td>${list.childTaxType }</td>
<td class="data">${list.data }</td>
<%-- <td><input type="text" value="${list.data }" name="data" id="data"></td> --%>
<%-- <td><input type="text" value="${list.fromSegments }" name="fromSegments" id="fromSegments"></td> --%>
<!-- <td><textarea name="fromSegments" value="{\"carrier\": \"MF\",\"stopAirports\": \"\",\"canbinClass\": 1,\"stopCities\": \"\",\"codeShare\": false}" id="fromSegments"></textarea></td> -->
<%-- <td>${list.fromSegments }</td> --%>
<td>
航司IATA二字码:${list.hc.carrier }
航班号:${list.hc.flightNumber }
出发机场IATA三字码 :${list.hc.depAirport }
起飞日期时间:${list.hc.depTime }1
到达机场IATA三字码 :${list.hc.arrAirport }
到达日期时间:${list.hc.arrTime }
经停地:${list.hc.stopCities }
代码共享标识:${list.hc.codeShare }
舱位 :${list.hc.cabin }
机型 :${list.hc.aircraftCode }
舱位等级:${list.hc.canbinClass }
经停时间:${list.hc.stopAirports }
</td>
<td>${list.nationality }</td>
<td>${list.nationalityType }</td>
<td>${list.priceType }</td>
<td>${list.rule }</td>
<%-- <td><input type="" value="${list.retSegments }" name="retSegments" id="retSegments"></td> --%>
<%-- <td><textarea name="retSegments" value="${list.retSegments}" id="retSegments"></textarea></td> --%>
<td class="retSegments">${list.retSegments}</td>
<td>${list.suitAge }</td>
<td>${list.ticketInvoiceType }</td>
<td>${list.ticketTimeLimit }</td>
<td style="display: none;"><input type="hidden" value="" name="cid" id="id" title="testqunar-正航test-qunar" ></td>
<td style="display: none;"><input class="tripTpye" type="hidden" value="" name="tripTpye" id="tripT"></td>
<td style="display: none;"><input class="adultNum" type="hidden" value="" name="adultNum" id="adultN"></td>
<td style="display: none;"><input class="childNum" type="hidden" value="" name="childNum" id="childN"></td>
<!-- <td><input type="hidden" value="" name="data" id="data2"></td>
<td><input type="hidden" value="" name="fromSegments" id="fromSegments2"></td>
<td><input type="hidden" value="" name="retSegments" id="retSegments2"></td> -->
<td><input id="input" type="button" value="验价" onclick="yj('${list.data}','${list.hc.carrier }','${list.hc.flightNumber }','${list.hc.depTime }','${list.hc.depAirport }','${list.hc.arrAirport }','${list.hc.arrTime }','${list.hc.stopCities }','${list.hc.codeShare }','${list.hc.cabin }','${list.hc.aircraftCode}')"></td>
</tr>
</c:forEach>
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
上面是index,jsp
servlet
public void verify(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
request.setCharacterEncoding("utf-8");
String url = "http://127.0.0.1:8082/order/priceVerify";
String data = request.getParameter("data");
String carrier = request.getParameter("carrier");
String flightNumber = request.getParameter("flightNumber");
String depAirport = request.getParameter("depAirport");
String depTime = request.getParameter("depTime");
String arrAirport = request.getParameter("arrAirport");
String arrTime = request.getParameter("arrTime");
String stopCities = request.getParameter("stopCities");
String codeShare = request.getParameter("codeShare");
String cabin = request.getParameter("cabin");
String aircraftCode = request.getParameter("aircraftCode");
HcMessageDTO hDto = new HcMessageDTO();
hDto.setCarrier(carrier);
hDto.setFlightNumber(flightNumber);
hDto.setDepAirport(depAirport);
hDto.setDepTime(depTime);
hDto.setArrAirport(arrAirport);
hDto.setArrTime(arrTime);
hDto.setStopCities(stopCities);
hDto.setCodeShare(codeShare);
hDto.setCabin(cabin);
hDto.setAircraftCode(aircraftCode);
JSONObject jo=new JSONObject();
jo.put("carrier", hDto.getCarrier());
jo.put("flightNumber", hDto.getFlightNumber());
jo.put("depAirport", hDto.getDepAirport());
jo.put("depTime", hDto.getDepTime());
jo.put("arrAirport", hDto.getArrAirport());
jo.put("arrTime", hDto.getArrTime());
jo.put("stopCities", hDto.getStopCities());
jo.put("codeShare", hDto.getCodeShare());
jo.put("cabin", hDto.getCabin());
jo.put("aircraftCode", hDto.getAircraftCode());
//将JSONObject转换成json
String json = jo.toString();
//构造person JSONObject数组
List<JSONObject> fromSegments=new ArrayList<JSONObject>();
fromSegments.add(jo);
JSONObject routing =new JSONObject();
routing.put("data", data);
routing.put("fromSegments", fromSegments);
JSONObject jsonObject = new JSONObject();
jsonObject.put("cid", id);
jsonObject.put("tripType",tripT);
jsonObject.put("adultNum", adultN);
jsonObject.put("childNum", childN);
jsonObject.put("routing", routing);
String json1=jsonObject.toString();
System.out.println(json1);
String httpResult = new HttpRequest().sendPost(url, json1.toString());
System.out.println(httpResult);
//先获取jsonobject对象
JSONObject jObject = JSONObject.parseObject(httpResult);
//从jsonobject对象中取出routing
String routings = jObject.getString("routing");
//jsonobject转java对象
Routing routing2 = JSON.parseObject(routings, Routing.class);
System.out.println("routing2+++++"+routing2);
Routing r = new Routing();
r.setAdultPrice(routing2.getAdultPrice());
System.out.println("getAdultPrice"+routing2.getAdultPrice());
r.setAdultTax(routing2.getAdultTax());
r.setAdultTaxType(routing2.getAdultTaxType());
r.setApplyType(routing2.getApplyType());
r.setChildPrice(routing2.getChildPrice());
r.setChildTax(routing2.getChildTax());
r.setChildTaxType(routing2.getChildTaxType());
r.setData(routing2.getData());
String fromSegment = routing2.getFromSegments();
//string转jsonarray
JSONArray jsonArray=JSONArray.parseArray(fromSegment);
System.out.println("jsonArray---"+jsonArray);
for (int i = 0; i < jsonArray.size(); i++) {
//jsonArray转jsonobject
JSONObject jsonObject2 = jsonArray.getJSONObject(i);
System.out.println("jsonObject2---"+jsonObject2);
//jsonobject转java对象
HcMessageDTO dto = JSONObject.toJavaObject(jsonObject2, HcMessageDTO.class);
HcMessageDTO hc=new HcMessageDTO();
hc.setAircraftCode(dto.getAircraftCode());
hc.setArrAirport(dto.getArrAirport());
hc.setArrTime(dto.getArrTime());
hc.setCabin(dto.getCabin());
hc.setCanbinClass(dto.getCanbinClass());
hc.setCarrier(dto.getCarrier());
hc.setCodeShare(dto.getCodeShare());
hc.setDepAirport(dto.getDepAirport());
hc.setDepTime(dto.getDepTime());
hc.setFlightNumber(dto.getFlightNumber());
hc.setStopAirports(dto.getStopAirports());
hc.setStopCities(dto.getStopCities());
List<HcMessageDTO> list = new ArrayList<HcMessageDTO>();
list.add(hc);
r.setFromSegment(list);
System.out.println("list+++"+list.toArray());
}
r.setNationality(routing2.getNationality());
r.setNationalityType(routing2.getNationalityType());
r.setPriceType(routing2.getPriceType());
r.setRetSegments(routing2.getPriceType());
r.setRetSegments(routing2.getRetSegments());
r.setSuitAge(routing2.getSuitAge());
r.setTicketInvoiceType(routing2.getTicketInvoiceType());
r.setTicketTimeLimit(routing2.getTicketTimeLimit());
System.out.println("routingLlist---"+r.getFromSegments());
System.out.println("routingLlist---"+r);
//从jsonobject对象中取出rule
String rule = jObject.getString("rule");
//jsonobject转java对象
Rules rules = JSONObject.parseObject(rule, Rules.class);
Rules ru = new Rules();
ru.setBaggage(rules.getBaggage());
ru.setEndorse(rules.getEndorse());
ru.setEndorsement(rules.getEndorsement());
ru.setHasBaggage(rules.getHasBaggage());
ru.setHasEndorse(rules.getHasEndorse());
ru.setHasNoShow(rules.getHasNoShow());
ru.setHasRefund(rules.getHasRefund());
ru.setNoShowLimitTime(rules.getNoShowLimitTime());
ru.setOther(rules.getOther());
ru.setPartEndorse(rules.getPartEndorse());
ru.setPartEndorsePrice(rules.getPartEndorsePrice());
ru.setPartRefund(rules.getPartRefund());
ru.setPartRefundPrice(rules.getPartRefundPrice());
ru.setPenalty(rules.getPenalty());
ru.setRefund(rules.getRefund());
ru.setSpecialNoShow(rules.getSpecialNoShow());
System.out.println("rules---"+ru);
Verify verify = JSONObject.toJavaObject(jObject, Verify.class);
Verify verifys = new Verify();
verifys.setMaxSeats(verify.getMaxSeats());
verifys.setRouting(r);
verifys.setRules(ru);
verifys.setSessionId(verify.getSessionId());
System.out.println(verify.getSessionId());
System.out.println();
JSONObject js = (JSONObject) JSONObject.toJSON(verifys);
String verifyJson = js.toJSONString();
System.out.println("verifyJson+++++"+verifyJson);
// request.setAttribute("verify", verifys);
PrintWriter out = response.getWriter();
out.println(verifyJson);
如何在seand.jsp 页面获取到数据,index.jsp中点击验价按钮然后跳到此方法查询,查出以后返回json(返回的数据是从一个接口里面获取到的,所以与传进去的数据不一样),success里面如何获取servlet返回的结果?并且把数据显示到seand.jsp页面上去
下面是seand.jsp
<body>
<%
Verify verify = (Verify)request.getAttribute("dataValue");
//String verify = request.getParameter("dataValue");
%>
<div class="zbss-table-wrapper table-responsive">
<form action="demo.do?type=verify" method="post" id="tf" class="formdata">
<table class="table table-striped table-hover table-condense" border="1" cellspacing="0">
<thead>
<tr>
<th>可预订的座位数</th>
<th>成人单价</th>
<th>成人税费</th>
<th>成人税费类型</th>
<th>报价类型</th>
<th>儿童单价</th>
<th>儿童税费</th>
<th>儿童税费类型</th>
<th>data</th>
<th>去程航段</th>
<th>乘客国籍</th>
<th>乘客国籍类型</th>
<th>报价类型</th>
<th>回程航段</th>
<th>适用乘客年龄</th>
<th>报销凭证类型</th>
<th>出票速度</th>
<th>退改签信息</th>
<th>会话标识</th>
<th style="display: none;">销售渠道</th>
<th style="display: none;">行程类型</th>
<th style="display: none;">订单来源</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<%-- <td><%=verify.getMaxSeats()%> </td> --%>
<td>${verify.getMaxSeats() }</td>
<td>${verify.getRouting().getAdultPrice() }</td>
<td>${verify.getRouting().getAdultTax() }</td>
<td>${verify.getRouting().getAdultTaxType() }</td>
<td>${verify.getRouting().getApplyType() }</td>
<td>${verify.getRouting().getChildPrice() }</td>
<td>${verify.getRouting().getChildTax() }</td>
<td>${verify.getRouting().getChildTaxType() }</td>
<td class="data">${verify.getRouting().getData() }</td>
<td>
航司IATA二字码:${verify.getRouting().getFromSegments().getCarrier() }
航班号:${verify.getRouting().getFromSegments().getFlightNumber() }
出发机场IATA三字码 :${verify.getRouting().getFromSegments().getDepAirport() }
起飞日期时间:${verify.getRouting().getFromSegments().getDepTime() }
到达机场IATA三字码 :${verify.getRouting().getFromSegments().getArrAirport() }
到达日期时间:${verify.getRouting().getFromSegments().getArrTime() }
经停地:${verify.getRouting().getFromSegments().getStopCities() }
代码共享标识:${verify.getRouting().getFromSegments().getCodeShare() }
舱位 :${verify.getRouting().getFromSegments().getCabin() }
机型 :${verify.getRouting().getFromSegments().getAircraftCode() }
舱位等级:${verify.getRouting().getFromSegments().getCanbinClass() }
经停时间:${verify.getRouting().getFromSegments().getStopAirports() }
</td>
<td>${verify.getRouting().getNationality() }</td>
<td>${verify.getRouting().getNationalityType() }</td>
<td>${verify.getRouting().getPriceType() }</td>
<td>${verify.getRouting().getRetSegments() }</td>
<td>${verify.getRouting().getSuitAge() }</td>
<td>${verify.getRouting().getTicketInvoiceType() }</td>
<td>${verify.getRouting().getTicketTimeLimit() }</td>
<td>
单程直飞时: ${verify.getRules().getBaggage() }
改签标准: ${verify.getRules().getEndorse() }
签转规则: ${verify.getRules().getEndorsement() }
是否提供免费行李额:${verify.getRules().getHasBaggage() }
是否允许改期:${verify.getRules().getHasEndorse() }
是否有noshow规则:${verify.getRules().getHasNoShow() }
是否允许退票:${verify.getRules().getHasRefund() }
Noshow时限:${verify.getRules().getNoShowLimitTime() }
其他事项:${verify.getRules().getOther() }
部分改期规则:${verify.getRules().getPartEndorse() }
部分改期费用:${verify.getRules().getPartEndorsePrice() }
部分退票规则:${verify.getRules().getPartRefund() }
部分退票费用:${verify.getRules().getPartRefundPrice() }
Noshow罚金:${verify.getRules().getPenalty() }
退款规则:${verify.getRules().getRefund() }
Noshow特殊规则:${verify.getRules().getSpecialNoShow() }
</td>
<td>${verify.getSessionId() }</td>
<td><input type="button" id="sd" value="生单" onclick="sd()"/></td>
</tr>
</tbody>
</table>
</form>
</div>
</body>