弹出一个登录层,并对登录进行校验

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="弹出层.aspx.cs" Inherits="弹出层" %>

<!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">
<head>
    <title></title>
    <!-- 这里一段JS的代码,主要是两个方法。一个是隐藏层。一个是打开层 -->

    <script language="javascript" type="text/javascript">
    
      function ShowDiv(){
     var Show = document.getElementById("login");
     Show.style.position = "absolute";
     Show.style.visibility = "visible";
     Show.style.display = "block";
}
function ClosDiv(){
var Clos = document.getElementById("login");
Clos.style.visibility = "hidden";
Clos.style.display = "none";
}
function LoginIn()
{
alert('a');
 var username=document.getElementById("username");
 var password=document.getElementById("passwodr");
 alert(username.value);
 alert(password.value);
 if(username.value=="admin"&&password.value=="admin")
 {
     window.location.href("Default.aspx");
 }
}
    </script>

</head>
<body>
    <a href="#" οnclick="ShowDiv()">登录</a> <a href="#" οnclick="ClosDiv()">取消</a>
    <div id="login" style="visibility: hidden; display: none; border: 1px #CCCCCC solid;
        width: 300px;">
        <div style="width: 300px; height: 20px; background-color: #CCCCFF; display: block">
            <div style="width: 5px; height: 5px; margin-left: 140px; margin-top: 5px;">
                <input type="submit" value="X" οnclick="ClosDiv()" width="2px;" height="2px;" />
            </div>
        </div>
        <div>
            <form action="">
                用户名:<input type="text" id="username" /><br />
                密 码:
                <input id="passwodr" type="password" /><br />
                <input id="btnlogin" type="button" value="登录" οnclick="LoginIn()" />&nbsp;&nbsp;&nbsp;
                <input type="reset" value="清空" />
                <input type="button" value="关闭" οnclick="ClosDiv()" />
            </form>
        </div>
    </div>
</body>
</html>

很抱歉,我作为一个语言模型,无法提供具体的程序代码。但我可以给你一些思路和步骤。 1. 创建数据库表,建立相应的实体类和DAO,使用Mybatis框架进行数据库操作。 2. 创建Service接口和实现类,实现抽奖逻辑,包括根据活动查询奖品,计算奖品概率,记录抽奖和中奖信息,校验用户和奖品信息等。 3. 创建Controller,提供RESTful API接口,调用Service实现抽奖功能。 4. 使用LotteryUtils工具类实现抽奖概率计算和随机抽奖。 5. 在Controller添加接口访问频率限制,在Service添加事务控制和异常处理,确保数据的一致性和完整性。 6. 需要注意的是,抽奖过程中需要校验奖品库存,避免出现库存不足的情况。 下面是一个简单的伪代码示例: ```java @RestController public class LotteryController { private static final int MAX_LOTTERY_TIMES = 3; private static final long MIN_ACCESS_INTERVAL = 10000L; @Autowired private LotteryService lotteryService; @PostMapping("/lottery") public Result<LotteryResult> lottery(@RequestBody LotteryRequest request, HttpServletRequest servletRequest) { String ip = servletRequest.getRemoteAddr(); // 校验接口访问频率 if (!AccessLimitUtils.tryAcquire(ip, MIN_ACCESS_INTERVAL)) { return Result.fail("too many requests, please try again later"); } // 校验用户和奖品信息 if (!lotteryService.validate(request.getUserId(), request.getPrizeId())) { return Result.fail("invalid user or prize"); } // 校验抽奖次数和活动状态 if (!lotteryService.checkLotteryTimes(request.getActivityId(), MAX_LOTTERY_TIMES)) { return Result.fail("exceed max lottery times or activity not started"); } // 执行抽奖逻辑 try { LotteryResult result = lotteryService.lottery(request.getActivityId(), request.getUserId(), request.getPrizeId()); return Result.success(result); } catch (Exception e) { return Result.fail("lottery failed"); } } } @Service @Transactional public class LotteryServiceImpl implements LotteryService { @Autowired private PrizeMapper prizeMapper; @Autowired private LotteryMapper lotteryMapper; @Autowired private WinningMapper winningMapper; @Override public boolean validate(long userId, long prizeId) { // 校验用户和奖品是否存在 User user = userDao.findById(userId); Prize prize = prizeDao.findById(prizeId); if (user == null || prize == null) { return false; } return true; } @Override public boolean checkLotteryTimes(long activityId, int maxTimes) { // 校验活动是否在进行中 Activity activity = activityDao.findById(activityId); if (activity == null || !activity.isStarted()) { return false; } // 校验抽奖次数 int lotteryTimes = lotteryMapper.getLotteryTimes(activityId); if (lotteryTimes >= maxTimes) { return false; } return true; } @Override public LotteryResult lottery(long activityId, long userId, long prizeId) { // 查询奖品信息 Prize prize = prizeMapper.findById(prizeId); // 计算中奖概率 double probability = LotteryUtils.calculateProbability(prize.getProbability()); // 随机抽奖 boolean win = LotteryUtils.lottery(probability); if (win) { // 记录中奖信息 Winning winning = new Winning(activityId, userId, prizeId); winningMapper.insert(winning); } // 记录抽奖信息 Lottery lottery = new Lottery(activityId, userId, prizeId, win); lotteryMapper.insert(lottery); return new LotteryResult(prize.getName(), win); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值