在我的專案中,我需要將從“Availability.java”中的資料庫中檢索到的“價格”值傳遞給“display.jsp”。我已經實作了,但問題是......我還需要通過從“display.jsp”到“seat.jsp”的“價格”值。當我嘗試時,它為價格變數回傳空值。
可用性.java
try {
response.setContentType("text/html;charset=UTF-8");
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bus","root","happy");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from availability");
String fp=request.getParameter("from");
String tp=request.getParameter("to");
String date = request.getParameter("date");
Boolean flag=false;
while(rs.next()){
String from=rs.getString("fromplace").toString();
String to=rs.getString("toplace").toString();
String datedb=rs.getString("date").toString();
String price=rs.getString("price").toString();
if(from.equals(fp) && to.equals(tp) && datedb.equals(date) )
{
//PrintWriter out=response.getWriter();
//out.print("Available");
request.setAttribute("from",from);
request.setAttribute("to",to);
request.setAttribute("date",date);
request.setAttribute("price",price);
request.getRequestDispatcher("display.jsp").forward(request, response);
flag=true;
break;
}
}
if(!flag) {
request.setAttribute("date",date);
request.getRequestDispatcher("Unavailable.jsp").forward(request, response);
}
顯示.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<table >
<tr class="icon">
<th>Fare</th>
</tr>
<tr>
<td id="p">INR ${price }</td>
</tr>
</table>
<center><a href="seat.jsp" class="button"> <span>View Seats </span></a></center>
座位.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<body>
<div class="wrapper">
<div class="container">
<div id="seat-map" class="seat-panel">
<div class="front-indicator">Front</div>
</div>
<div class="booking-details">
<h2>Booking Details</h2>
<h3> Selected Seats (<span id="counter">0</span>):</h3>
<ul id="selected-seats"> </ul>
Total: <b>Rs.<span id="total">0</span></b>
<button class="checkout-button">Checkout »</button>
<div id="legend"></div>
</div>
</div>
</div>
<script>
var firstSeatLabel = 1;
$(document).ready(function() {
var $cart = $('#selected-seats'),
$counter = $('#counter'),
$total = $('#total'),
sc = $('#seat-map').seatCharts({
map: [
'ff_ff',
'ff_ff',
'ee_ee',
'ee_ee',
'ee___',
'ee_ee',
'ee_ee',
'ee_ee',
'eeeee',
],
seats: {
f: {
price :document.getElementById("p"),
},
e: {
price : document.getElementById("p"),
},
},
naming : {
top : false,
getLabel : function (character, row, column) {
return firstSeatLabel ;
},
},
legend : {
node : $('#legend'),
items : [
[ 'f', 'available', 'Available' ],
[ 'f', 'unavailable', 'Already Booked']
]
},
click: function () {
if (this.status() == 'available') {
$('<li> Seat - ' this.settings.label ': <b>$' this.data().price '</b> <a href="#" >[cancel]</a></li>')
.attr('id', 'cart-item-' this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
$counter.text(sc.find('selected').length 1);
$total.text(recalculateTotal(sc) this.data().price);
return 'selected';
} else if (this.status() == 'selected') {
$counter.text(sc.find('selected').length-1);
$total.text(recalculateTotal(sc)-this.data().price);
$('#cart-item-' this.settings.id).remove();
return 'available';
} else if (this.status() == 'unavailable') {
return 'unavailable';
} else {
return this.style();
}
}
});
$('#selected-seats').on('click', '.cancel-cart-item', function () {
sc.get($(this).parents('li:first').data('seatId')).click();
});
});
function recalculateTotal(sc) {
var total = 0;
sc.find('selected').each(function () {
total = this.data().price;
});
return total;
}
</script>
我怎樣才能做到這一點?
請回答我的問題!立即回應是可觀的。
先感謝您:)
uj5u.com熱心網友回復:
在 display.jsp 中,在 href 中,您可以有一個 servlet 而不是另一個 jsp 頁面,并且該 servlet 可以將您需要的值作為 requestParameter 傳遞,并且您可以執行轉發到您的 seat.jsp。然后,您可以在 seat.jsp 中讀取您需要的引數。
我希望這會有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490791.html
