简体   繁体   English

JSP 页面中的增量变量

[英]Increment variable in JSP page

I am working on a flight reservation system.我正在研究航班预订系统。

In my sql database, I have a table called ticket where there is a column called seatnum.在我的 sql 数据库中,我有一个名为 ticket 的表,其中有一列名为 seatnum。 I have another table called aircraft and that has a column called seats.我还有一张叫做飞机的桌子,里面有一列叫做座位。

In my jsp page, I want to assign a random seat number to a person buying a ticket, but I can only assign so many seats before the seats in the aircraft table gets full.在我的 jsp 页面中,我想为买票的人分配一个随机座位号,但我只能在飞机表中的座位满之前分配这么多座位。

I want to declare a global counter for the number of seats I assign to a particular flight, but my counter keeps being reset to 0 but I can't declare a static variable in a jsp.我想为分配给特定航班的座位数声明一个全局计数器,但我的计数器一直重置为 0,但我无法在 jsp 中声明 static 变量。 What should I do instead?我应该怎么做?


CREATE TABLE `ticket` (
  `cid` int,
  `flight_num` int,
  `ticket_num` int NOT NULL AUTO_INCREMENT,
  `seatnum` int, 
PRIMARY KEY (`ticket_num`),
FOREIGN KEY (`flight_num`) REFERENCES flight (`flight_num`) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`cid`) REFERENCES user (`cid`) ON UPDATE CASCADE ON DELETE CASCADE
) 

CREATE TABLE `aircraft` (
    `2letterid` varchar(2),
    `aircraft_num` int,
    `seats` int,
PRIMARY KEY (`2letterid`, `aircraft_num`),
FOREIGN KEY(`2letterid`) REFERENCES `airline` (`2letterid`)
) 

int counter = 0;
String seats = "select seats from flight join aircraft(flight_num) " +
                "where flight_num = " + flightNum;

if (counter > seats) {
enter a waiting list
}

You can store the counter in a hidden field or in the session.您可以将计数器存储在隐藏字段或 session 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM