地铁线路管理系统

 

下面是地铁线路管理系统实现代码:

 

后台代码实现:

package com.bean;
//站点类
public class Bean {
    private int lineid;//线路号
    private String stationname;//站点名
    private int tinformation;//换乘   该站点所在的另一条线路
    private int ordnum;//站点顺序

    public void setLineid(int lineid){
        this.lineid = lineid;
    }
    public int getLineid() {
        return lineid;
    }
    public void setStationname(String stationname){
        this.stationname = stationname;
    }
    public String getStationname() {
        return stationname;
    }
    public void setTinformation(int tinformation){
        this.tinformation = tinformation;
    }
    public int getTinformation() {
        return tinformation;
    }
    public void setOrdnum(int ordnum){
        this.ordnum = ordnum;
    }
    public int getOrdnum() {
        return ordnum;
    }
}

 

package com.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.DBUtil.SubwayDBUtil;
//算法
public class DataBuilder {
    public static List<Station> line1 = new ArrayList<Station>();//1号线
    public static List<Station> line2 = new ArrayList<Station>();//2号线
    public static List<Station> line3 = new ArrayList<Station>();//3号线
    public static List<Station> line4 = new ArrayList<Station>();//4号线
    public static List<Station> line5 = new ArrayList<Station>();//5号线
    public static List<Station> line6 = new ArrayList<Station>();//6号线
    public static Set<List<Station>> lineSet = new HashSet<List<Station>>();//所有线集合
    public static int totalStaion = 0;//总的站点数量
    static {
        /*******************************************************************************/
        //1号线
        String[] line1Arr = new String[29];
        Connection conn1 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn1.createStatement();
            String sql = "select * from line where lineid=1";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line1Arr[k] = rs.getString("stationname");
                k++;
            }
            conn1.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line1Arr) {
            line1.add(new Station(s));
        }
        for(int i =0;i<line1.size();i++) {
            if(i<line1.size()-1) {
                line1.get(i).next = line1.get(i+1);
                line1.get(i+1).prev = line1.get(i);
            }
        }

        /*******************************************************************************/
        //2号线
        String[] line2Arr = new String[37];
        Connection conn2 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn2.createStatement();
            String sql = "select * from line where lineid=2";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line2Arr[k] = rs.getString("stationname");
                k++;
            }
            conn2.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line2Arr) {
            line2.add(new Station(s));
        }
        for(int i =0;i<line2.size();i++) {
            if(i<line2.size()-1) {
                line2.get(i).next = line2.get(i+1);
                line2.get(i+1).prev = line2.get(i);
            }
        }

        /*******************************************************************************/
        //3号线
        String[] line3Arr = new String[35];
        Connection conn3 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn3.createStatement();
            String sql = "select * from line where lineid=3";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line3Arr[k] = rs.getString("stationname");
                k++;
            }
            conn3.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line3Arr) {
            line3.add(new Station(s));
        }
        for(int i =0;i<line3.size();i++) {
            if(i<line3.size()-1) {
                line3.get(i).next = line3.get(i+1);
                line3.get(i+1).prev = line3.get(i);
            }
        }

        /*******************************************************************************/
        //4号线
        String[] line4Arr = new String[18];
        Connection conn4 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn4.createStatement();
            String sql = "select * from line where lineid=4";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line4Arr[k] = rs.getString("stationname");
                k++;
            }
            conn4.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line4Arr) {
            line4.add(new Station(s));
        }
        for(int i =0;i<line4.size();i++) {
            if(i<line4.size()-1) {
                line4.get(i).next = line4.get(i+1);
                line4.get(i+1).prev = line4.get(i);
            }
        }

        /*******************************************************************************/
        //5号线
        String[] line5Arr = new String[21];
        Connection conn5 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn5.createStatement();
            String sql = "select * from line where lineid=5";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line5Arr[k] = rs.getString("stationname");
                k++;
            }
            conn5.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line5Arr) {
            line5.add(new Station(s));
        }
        for(int i =0;i<line5.size();i++) {
            if(i<line5.size()-1) {
                line5.get(i).next = line5.get(i+1);
                line5.get(i+1).prev = line5.get(i);
            }
        }

        /*******************************************************************************/
        //s8号线
        String[] line6Arr = new String[19];
        Connection conn6 = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn6.createStatement();
            String sql = "select * from line where lineid=6";
            ResultSet rs = stmt.executeQuery(sql);
            int k = 0;
            while(rs.next()) {
                line6Arr[k] = rs.getString("stationname");
                k++;
            }
            conn6.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        for(String s : line6Arr) {
            line6.add(new Station(s));
        }
        for(int i =0;i<line6.size();i++) {
            if(i<line6.size()-1) {
                line6.get(i).next = line6.get(i+1);
                line6.get(i+1).prev = line6.get(i);
            }
        }

        /*******************************************************************************/
        lineSet.add(line1);
        lineSet.add(line2);
        lineSet.add(line3);
        lineSet.add(line4);
        lineSet.add(line5);
        lineSet.add(line6);
        totalStaion  = line1.size() + line2.size() + line3.size() + line4.size() + line5.size() + line6.size();
        System.out.println("总的站点数量:"+totalStaion);
    }
    public static void main(String[] args) {

        System.out.println("总的站点数量:"+totalStaion);
    }
}

 

package com.dao;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
//算法
public class Station {
    private String name; //地铁站名称,假设具备唯一性
    public Station prev; //本站在lineNo线上面的前一个站
    public Station next; //本站在lineNo线上面的后一个站

    //本站到某一个目标站(key)所经过的所有站集合(value),保持前后顺序
    private Map<Station,LinkedHashSet<Station>> orderSetMap = new HashMap<Station,LinkedHashSet<Station>>();

    public Station (String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LinkedHashSet<Station> getAllPassedStations(Station station) {
        if(orderSetMap.get(station) == null) {
            LinkedHashSet<Station> set = new LinkedHashSet<Station>();
            set.add(this);
            orderSetMap.put(station, set);
        }
        return orderSetMap.get(station);
    }

    public Map<Station, LinkedHashSet<Station>> getOrderSetMap() {
        return orderSetMap;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        else if(obj instanceof Station) {
            Station s = (Station) obj;
            if(s.getName().equals(this.getName())) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }


    @Override
    public int hashCode() {
        return this.getName().hashCode();
    }

}

 

 

package com.dao;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import com.bean.Bean;
//算法
public class Subway {

    private List<Station> outList = new ArrayList<Station>();//记录已经分析过的站点

    //计算从s1站到s2站的最短经过路径
    public List<Bean> calculate(Station s1, Station s2){

        List<Bean> list = new ArrayList<Bean>();//用于返回路径信息

        if(outList.size() == DataBuilder.totalStaion){
            System.out.println("找到目标站点:"+s2.getName()+",共经过"+(s1.getAllPassedStations(s2).size()-1)+"站");
            for(Station station : s1.getAllPassedStations(s2)){
                System.out.print(station.getName()+"->");
                Bean bean = new Bean();
                bean.setStationname(station.getName());
                list.add(bean);
            }
            return list;
        }
        if(!outList.contains(s1)){
            outList.add(s1);
        }
        //如果起点站的OrderSetMap为空,则第一次用起点站的前后站点初始化之
        if(s1.getOrderSetMap().isEmpty()){
            List<Station> Linkedstations = getAllLinkedStations(s1);
            for(Station s : Linkedstations){
                s1.getAllPassedStations(s).add(s);
            }
        }
        Station parent = getShortestPath(s1);//获取距离起点站s1最近的一个站(有多个的话,随意取一个)
        if(parent == s2){
            System.out.println("找到目标站点:"+s2+",共经过"+(s1.getAllPassedStations(s2).size()-1)+"站");
            for(Station station : s1.getAllPassedStations(s2)){
                System.out.print(station.getName()+"->");
                Bean bean = new Bean();
                bean.setStationname(station.getName());
                list.add(bean);
            }
            return list;
        }
        for(Station child : getAllLinkedStations(parent)){
            if(outList.contains(child)){
                continue;
            }
            int shortestPath = (s1.getAllPassedStations(parent).size()-1) + 1;//前面这个1表示计算路径需要去除自身站点,后面这个1表示增加了1站距离
            if(s1.getAllPassedStations(child).contains(child)){
                //如果s1已经计算过到此child的经过距离,那么比较出最小的距离
                if((s1.getAllPassedStations(child).size()-1) > shortestPath){
                    //重置S1到周围各站的最小路径
                    s1.getAllPassedStations(child).clear();
                    s1.getAllPassedStations(child).addAll(s1.getAllPassedStations(parent));
                    s1.getAllPassedStations(child).add(child);
                }
            } else {
                //如果s1还没有计算过到此child的经过距离
                s1.getAllPassedStations(child).addAll(s1.getAllPassedStations(parent));
                s1.getAllPassedStations(child).add(child);
            }
        }
        outList.add(parent);
        return calculate(s1,s2);
    }

    //取参数station到各个站的最短距离,相隔1站,距离为1,依次类推
    private Station getShortestPath(Station station){
        int minPatn = Integer.MAX_VALUE;
        Station rets = null;
        for(Station s :station.getOrderSetMap().keySet()){
            if(outList.contains(s)){
                continue;
            }
            LinkedHashSet<Station> set  = station.getAllPassedStations(s);//参数station到s所经过的所有站点的集合
            if(set.size() < minPatn){
                minPatn = set.size();
                rets = s;
            }
        }
        return rets;
    }

    //获取参数station直接相连的所有站,包括交叉线上面的站
    private List<Station> getAllLinkedStations(Station station){
        List<Station> linkedStaions = new ArrayList<Station>();
        for(List<Station> line : DataBuilder.lineSet){
            if(line.contains(station)){//如果某一条线包含了此站,注意由于重写了hashcode方法,只有name相同,即认为是同一个对象
                Station s = line.get(line.indexOf(station));
                if(s.prev != null){
                    linkedStaions.add(s.prev);
                }
                if(s.next != null){
                    linkedStaions.add(s.next);
                }
            }
        }
        return linkedStaions;
    }

}

 

 

package com.DBUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//数据库连接
public class SubwayDBUtil {
    public static String db_url="jdbc:mysql://localhost:3306/subway?useSSL=true&serverTimezone=UTC";//这是连接数据库,userdome是数据库的名称,userUnicode=true&characterEncoding=UTF-8是将字符集设置为utf-8,避免乱码。
    public static String db_user="root";//数据的用户名
    public static String db_password="123456";//数据库的密码
    public static Connection getConn()//获取连接,返回Connection类型,必须设置为static这样才能在其他类中使用
    {
        Connection conn=null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");//加载驱动
            conn=DriverManager.getConnection(db_url,db_user,db_password);//连接数据库
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return conn;
    }

    public static void close(Statement state,Connection conn)//关闭函数
    {
        if(state!=null)//只有状态和连接时,先关闭状态
        {
            try
            {
                state.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
        }
        if(conn!=null)
        {
            try
            {
                conn.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
        }
    }

    public static void close(ResultSet rs,Statement state,Connection conn)
    {

        if(rs!=null)//有结果集,状态和连接时,先关闭结果集,在关闭状态,在关闭连接
        {
            try
            {
                rs.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
        }

        if(state!=null)

        {
            try
            {
                state.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
        }

        if(conn!=null)
        {
            try
            {
                conn.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
        }
    }

}

 

 

package com.servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.DBUtil.SubwayDBUtil;
import com.bean.*;
import com.dao.*;
//服务类
public class SearchServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
@Override
    protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        searchSubway1(req, resp);
        searchSubway2(req, resp);
        req.getRequestDispatcher("/search.jsp").forward(req, resp);
    }

    public void searchSubway1(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {//换乘最少
        req.setCharacterEncoding("UTF-8");

        String start;
        String end;

        start = req.getParameter("start");
        end = req.getParameter("end");

        Bean beanstart=new Bean();
        Bean beanend=new Bean();
        List<Bean> list = new ArrayList<>();//存放线路

        HttpSession session = req.getSession();

        Connection conn = SubwayDBUtil.getConn();
        try {
            Statement stmt = conn.createStatement();
            String sql = "select * from line";
            ResultSet rs = stmt.executeQuery(sql);

            while(rs.next()) {
                if(start.equals(rs.getString("stationname"))) {
                    beanstart.setLineid(rs.getInt("lineid"));
                    beanstart.setStationname(rs.getString("stationname"));
                    beanstart.setTinformation(rs.getInt("tinformation"));
                    beanstart.setOrdnum(rs.getInt("ordnum"));
                }

                if(end.equals(rs.getString("stationname"))) {
                    beanend.setLineid(rs.getInt("lineid"));
                    beanend.setStationname(rs.getString("stationname"));
                    beanend.setTinformation(rs.getInt("tinformation"));
                    beanend.setOrdnum(rs.getInt("ordnum"));
                }
            }

            if(beanstart.getLineid() == beanend.getLineid()) {//在同一条线上
                if(beanstart.getOrdnum() > beanend.getOrdnum()) {//起始站的order比终点站的order大
                    int startorder = beanstart.getOrdnum();//起始站的order
                    int endorder = beanend.getOrdnum();//终点站的order
                    int lineid = beanstart.getLineid();//线路号

                    String sql1 = "select * from line where ordnum <='"+startorder+"' and ordnum >='"+endorder+"' and lineid ='"+lineid+"' order by ordnum desc";
                    ResultSet rs1 = stmt.executeQuery(sql1);

                    while(rs1.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs1.getString("stationname"));
                        list.add(bean);
                    }
                    session.setAttribute("list",list);//传值
                }
                else if(beanstart.getOrdnum() < beanend.getOrdnum()) {//起始站的order比终点站的order小
                    int startorder = beanstart.getOrdnum();//起始站的order
                    int endorder = beanend.getOrdnum();//终点站的order
                    int lineid = beanstart.getLineid();//线路号

                    String sql1 = "select * from line where ordnum >='"+startorder+"' and ordnum <='"+endorder+"' and lineid ='"+lineid+"' order by ordnum asc";
                    ResultSet rs1 = stmt.executeQuery(sql1);

                    while(rs1.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs1.getString("stationname"));
                        list.add(bean);
                    }
                    session.setAttribute("list",list);//传值
                }
            }
            else if(beanstart.getLineid() != beanend.getLineid()) {//不在同一条线上
                Bean beantemp = new Bean();

                //以起始站所在线为标准,找换乘站
                String sql1 = "select * from line where lineid='"+beanstart.getLineid()+"' and tinformation='"+beanend.getLineid()+"'";
                ResultSet rs1 = stmt.executeQuery(sql1);

                while(rs1.next()) {
                    beantemp.setLineid(rs1.getInt("lineid"));
                    beantemp.setStationname(rs1.getString("stationname"));
                    beantemp.setTinformation(rs1.getInt("tinformation"));
                    beantemp.setOrdnum(rs1.getInt("ordnum"));
                }

                if(beanstart.getOrdnum() > beantemp.getOrdnum()) {//起始站的order比换乘站的order大
                    int startorder = beanstart.getOrdnum();//起始站的order
                    int temporder = beantemp.getOrdnum();//换乘站的order
                    int lineid = beanstart.getLineid();//线路号

                    String sql2 = "select * from line where ordnum <='"+startorder+"' and ordnum >='"+temporder+"' and lineid ='"+lineid+"' order by ordnum desc";
                    ResultSet rs2 = stmt.executeQuery(sql2);

                    while(rs2.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs2.getString("stationname"));
                        list.add(bean);
                    }
                }
                else if(beanstart.getOrdnum() < beantemp.getOrdnum()) {//起始站的order比换乘站的order小
                    int startorder = beanstart.getOrdnum();//起始站的order
                    int temporder = beantemp.getOrdnum();//换乘站的order
                    int lineid = beanstart.getLineid();//线路号

                    String sql2 = "select * from line where ordnum >='"+startorder+"' and ordnum <='"+temporder+"' and lineid ='"+lineid+"' order by ordnum asc";
                    ResultSet rs2 = stmt.executeQuery(sql2);

                    while(rs2.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs2.getString("stationname"));
                        list.add(bean);
                    }
                }

                //以终点站所在线为标准,找换乘站
                String sql3 = "select * from line where lineid='"+beanend.getLineid()+"' and tinformation='"+beanstart.getLineid()+"'";
                ResultSet rs3 = stmt.executeQuery(sql3);

                while(rs3.next()) {
                    beantemp.setLineid(rs3.getInt("lineid"));
                    beantemp.setStationname(rs3.getString("stationname"));
                    beantemp.setTinformation(rs3.getInt("tinformation"));
                    beantemp.setOrdnum(rs3.getInt("ordnum"));
                }

                if(beantemp.getOrdnum() > beanend.getOrdnum()) {//换乘站的order比终点站的order大
                    int temporder = beantemp.getOrdnum();//换乘站的order
                    int endorder = beanend.getOrdnum();//终点站的order
                    int lineid = beanend.getLineid();//线路号

                    String sql2 = "select * from line where ordnum <='"+temporder+"' and ordnum >='"+endorder+"' and lineid ='"+lineid+"' order by ordnum desc";
                    ResultSet rs2 = stmt.executeQuery(sql2);

                    while(rs2.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs2.getString("stationname"));
                        list.add(bean);
                    }
                }
                else if(beantemp.getOrdnum() < beanend.getOrdnum()) {//换乘站的order比终点站的order小
                    int temporder = beantemp.getOrdnum();//换乘站的order
                    int endorder = beanend.getOrdnum();//终点站的order
                    int lineid = beanend.getLineid();//线路号

                    String sql2 = "select * from line where ordnum >='"+temporder+"' and ordnum <='"+endorder+"' and lineid ='"+lineid+"' order by ordnum asc";
                    ResultSet rs2 = stmt.executeQuery(sql2);

                    while(rs2.next()) {
                        Bean bean = new Bean();
                        bean.setStationname(rs2.getString("stationname"));
                        list.add(bean);
                    }
                }

                session.setAttribute("list",list);//传值
            }
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void searchSubway2(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");

        String start;
        String end;

        start = req.getParameter("start");
        end = req.getParameter("end");

        List<Bean> list2 = new ArrayList<>();//存放线路

        HttpSession session = req.getSession();

        Subway sw = new Subway();
        Station s1 = new Station(start);
        Station s2 = new Station(end);
        list2 = sw.calculate(s1, s2);

        session.setAttribute("list2",list2);//传值
    }

}

 

前端文件

<%--
  Created by IntelliJ IDEA.
  User: Tefuir
  Date: 2022/4/2
  Time: 22:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.HttpSession" %>
<%@page import="javax.servlet.http.HttpServletResponse" %>
<%@page import="javax.servlet.http.HttpServletRequest" %>
<%@page import="com.bean.*" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>查询</title>

    <style type="text/css">

        div h2{
            background-color: aqua;
        }

        div{
            background-color: antiquewhite;
            width:380px;
            height:300px;
            border-radius:5px;
        }

        div p{
            font-family: "Microsoft New Tai Lue";
            font-size:20px;
            color: grey;
        }

        div p input{
            height:20px;
            border-radius:3px;
            border:0px;
        }

        #check{
            width:70px;
            height:25px;
            border-radius:3px;
            color:white;
            background-color: #6699CC;
            text-align:center;
            text-decoration:none;
            border:none;
            position:relative;
            left:90px;
        }

        #check:hover{
            background-color: #303030;
        }

        #information{
            width:260px;
            height:250px;
            border-radius:3px;
            display:block;
            margin:0 auto;
            font-family: "Microsoft New Tai Lue";
            font-size:10px;
        }

    </style>

</head>
<body>

<div>
    <form action="${pageContext.request.contextPath}/servlet/SearchServlet" method="post" onsubmit="return oncheck()">

        <br/>
        <h2>北京地铁</h2>

        <br/>
        <p>  起始站
            <br/>
            <input type="text" name="start" id="start" placeholder="    请输入起始站">
        </p>

        <p>  终点站
            <br/>
            <input type="text" name="end" id="end" placeholder="    请输入终点站">
        </p>

        <p><input type="submit" value="查询" name="check" id="check"></p>
        <p>线路信息</p>
        <%--<textarea name="information" id="information" readonly="readonly">
        </textarea>--%>
    </form>
</div>


<script type="text/javascript">

    function oncheck() {
        var start = document.getElementById("start");
        var end = document.getElementById("end");
        var strstart = start.value;
        var strend = end.value;

        if(strstart == '') {
            alert('起始站为空');
            start.focus();
            return false;
        }
        if(strend == '') {
            alert('终点站为空');
            end.focus();
            return false;
        }

        return true;
    }

</script>
</body>
</html>

 

<%--
  Created by IntelliJ IDEA.
  User: Tefuir
  Date: 2022/4/2
  Time: 22:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>框架</title>

    <style type="text/css">
        .searchframe{
            width:100%;
            height:500px;
            border:0;
        }
    </style>
</head>

<body>
<iframe src="beginsearch.jsp" class="searchframe" scrolling="no"></iframe>
</body>

</html>

 

 

<%--
  Created by IntelliJ IDEA.
  User: Tefuir
  Date: 2022/4/2
  Time: 22:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>框架</title>

    <style type="text/css">
        body{
            background-color: aliceblue;
            width:100%;
            height:100%;
        }

        .leftframe{
            position:absolute;
            background-color: antiquewhite;
            float:left;
            width:20%;
            height:500px;
        }
        .rightframe{
            position:absolute;
            background-color: #E8EAF6;
            float:right;
            width:80%;
            height:500px;;
            margin-left:20%;
        }

    </style>
</head>
<body>
<div>
<iframe src="index_in.jsp" class="leftframe" scrolling="no" name="mainAction"></iframe>
<iframe src="map.html" class="rightframe" scrolling="no"></iframe>
</div>
</body>
</html>

 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/index.css">
</head>

<body>

<svg id="mobile-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="g-box" font-size="10"></g>
</svg>
<select></select>

</body>
<script src="libs/svg-pan-zoom.js"></script>
<script src="libs/hammer.min.js"></script>
<script src="libs/jquery.js"></script>
<script src="libs/limitTextNum.js"></script>
<script src="js/data.js"></script>
<script src="js/subway-painter.js"></script>

</html>

 

 

<%--
  Created by IntelliJ IDEA.
  User: Tefuir
  Date: 2022/4/2
  Time: 22:19
  To change this template use File | Settings | File Templates.
--%>
<%@page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.HttpSession" %>
<%@page import="javax.servlet.http.HttpServletResponse" %>
<%@page import="javax.servlet.http.HttpServletRequest" %>
<%@page import="com.bean.*" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>搜索线路&显示线路</title>

    <style type="text/css">

        div{
            background-color:#3F51B5;
            width:300px;
            height:500px;
            border-radius:5px;
        }

        div p{
            font-family:YouYuan;
            font-size:20px;
            color:#E8EAF6;
        }

        div p input{
            height:20px;
            border-radius:3px;
            border:0px;
        }

        #check{
            width:70px;
            height:25px;
            border-radius:3px;
            color:white;
            background-color:#004D99;
            text-align:center;
            text-decoration:none;
            border:none;
            position:relative;
            left:110px;
        }

        #check:hover{
            background-color:#6699CC;
        }

        #information{
            width:260px;
            height:300px;
            border-radius:3px;
            display:block;
            margin:0 auto;
            font-family:YouYuan;
            font-size:13px;
        }

    </style>

</head>
<body>

<div>
    <form action="${pageContext.request.contextPath}/servlet/SearchServlet" method="post" onsubmit="return oncheck()">
        <br/>
        <p>  起始站:
            <input type="text" name="start" id="start" placeholder="  Starting station">
        </p>
        <p>  终点站:
            <input type="text" name="end" id="end" placeholder="  Ending station">
        </p>
        <p><input type="submit" value="查询" name="check" id="check"></p>
        <textarea name="information" id="information" readonly="readonly">
线路信息:
<hr/>
换乘最少:
<%List<Bean> l = (List<Bean>)session.getAttribute("list");int num=l.size();%>
<%for(int i=0; i<l.size(); i++){%>
<%=l.get(i).getStationname()%><%if((i+1 < l.size()) && l.get(i).getStationname().equals(l.get(i+1).getStationname())){ num=num-1;%><%="(换乘)"%><%}%>
<%}%>
<%="(共"+num+"站)" %>
------------------------------
站点最少:
<%List<Bean> l2 = (List<Bean>)session.getAttribute("list2");int num2=l2.size();%>
<%for(int i=0; i<l2.size(); i++){%>
<%=l2.get(i).getStationname()%>
<%}%>
<%="(共"+num2+"站)" %>
------------------------------
        </textarea>
    </form>
</div>

<script type="text/javascript">


    function oncheck() {

        var start = document.getElementById("start");
        var end = document.getElementById("end");
        var strstart = start.value;
        var strend = end.value;

        if(strstart == '') {
            alert('起始站为空');
            start.focus();
            return false;
        }
        if(strend == '') {
            alert('终点站为空');
            end.focus();
            return false;
        }
        if(strstart != (
            '苹果园'||'古城'||'八角游乐园'||'八宝山'||'玉泉路'||'五棵松'||'万寿路'||'公主坟'||'军事博物馆'||'木樨地'||'南礼士路'||'复兴门'||'西单'||'天安门西'||'天安门东'||'王府井'||'东单'||'建国门'||'永安里'||'国贸'||'大望路'||'四惠'||'四惠东'||'高碑店'||'传媒大学'||'双桥'||'管庄'||'八里桥'||'通州北苑'||'果园'||'九棵树'||'梨园'||'临河里'||'土桥'||'花庄'||''||'环球度假区'
        )){
            alert('起始站错误');
            start.focus();
            return false;
        }
        if(strend != (
            '苹果园'||'古城'||'八角游乐园'||'八宝山'||'玉泉路'||'五棵松'||'万寿路'||'公主坟'||'军事博物馆'||'木樨地'||'南礼士路'||'复兴门'||'西单'||'天安门西'||'天安门东'||'王府井'||'东单'||'建国门'||'永安里'||'国贸'||'大望路'||'四惠'||'四惠东'||'高碑店'||'传媒大学'||'双桥'||'管庄'||'八里桥'||'通州北苑'||'果园'||'九棵树'||'梨园'||'临河里'||'土桥'||'花庄'||''||'环球度假区'
        )){
            alert('终点站错误');
            end.focus();
            return false;
        }
        return true;
    }

</script>
</body>
</html>

 

posted @ 2022-03-16 22:28  kuaiquxie  阅读(234)  评论(0编辑  收藏  举报