学校作业——通过tomcat写个jps登录

前言

暑期项目实习第三课,用web写个简单的登陆页面.

 

思路

tomcat是一个容器,我们通过设置将其运行在8080节点,而后做一个简单的post方法实现登录功能

 

配置

 

创建login jps需要的组件

<%--
  Created by IntelliJ IDEA.
  User: Aroad
  Date: 2020/6/29
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <form action="/login" method="post">
      username:<input name="username" type="text">
      password:<input n
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JPS算法(Jump Point Search)是一种基于A*算法的优化算法,用于解决地图路径规划问题。它的主要优势在于通过对地图进行预处理,可以有效减少搜索空间,提高搜索效率。 以下是使用JavaScript实现的JPS算法: ```javascript // 定义节点类 class Node { constructor(x, y, parent = null) { this.x = x; this.y = y; this.parent = parent; this.g = 0; this.h = 0; } // 计算节点的f值 get f() { return this.g + this.h; } // 估算从当前节点到终点的距离 estimateDistance(goal) { return Math.abs(this.x - goal.x) + Math.abs(this.y - goal.y); } // 判断当前节点是否为起点 isStart() { return this.parent === null; } // 判断当前节点是否与父节点在同一直线上 isStraight(parent) { return this.x === parent.x || this.y === parent.y; } // 判断当前节点是否为障碍物 isObstacle(grid) { return grid[this.y][this.x] === 1; } // 获取当前节点的邻居节点 getNeighbors(grid) { const neighbors = []; // 8个方向 const directions = [ [-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1], ]; for (const direction of directions) { const [dx, dy] = direction; const x = this.x + dx; const y = this.y + dy; // 判断邻居节点是否越界或为障碍物 if ( x < 0 || x >= grid[0].length || y < 0 || y >= grid.length || new Node(x, y).isObstacle(grid) ) { continue; } const neighbor = new Node(x, y, this); // 对于直线上的邻居节点,跳跃到下一个关键节点 if (this.isStraight(neighbor.parent)) { const dx = x - neighbor.parent.x; const dy = y - neighbor.parent.y; const nx = x + dx; const ny = y + dy; if ( nx >= 0 && nx < grid[0].length && ny >= 0 && ny < grid.length && !new Node(nx, ny).isObstacle(grid) ) { neighbors.push(new Node(nx, ny, this)); } } else { neighbors.push(neighbor); } } return neighbors; } // 获取从起点到当前节点的路径 getPath() { const path = []; let node = this; while (node) { path.unshift([node.x, node.y]); node = node.parent; } return path; } } // 定义JPS算法类 class JPS { constructor(grid) { this.grid = grid; this.openList = []; this.closedSet = new Set(); } // 寻找路径 findPath(start, goal) { const startNode = new Node(start[0], start[1]); const goalNode = new Node(goal[0], goal[1]); this.openList.push(startNode); while (this.openList.length > 0) { // 从openList中选择f值最小的节点 const currentNode = this.openList.sort((a, b) => a.f - b.f)[0]; // 到达终点,返回路径 if (currentNode.x === goalNode.x && currentNode.y === goalNode.y) { return currentNode.getPath(); } this.openList = this.openList.filter( (node) => node !== currentNode ); this.closedSet.add(currentNode); // 扩展邻居节点 for (const neighbor of currentNode.getNeighbors(this.grid)) { if (this.closedSet.has(neighbor)) { continue; } const gScore = currentNode.g + 1; if (!this.openList.includes(neighbor)) { this.openList.push(neighbor); } else if (gScore >= neighbor.g) { continue; } // 更新节点信息 neighbor.g = gScore; neighbor.h = neighbor.estimateDistance(goalNode); } } return null; } } ``` 使用示例: ```javascript const grid = [ [0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], ]; const jps = new JPS(grid); const path = jps.findPath([0, 0], [4, 4]); console.log(path); // [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]] ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值