完成了通过地铁线路号查询地铁站和通过地铁站chaxun线路
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import javax.swing.text.html.HTML;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/point")
public class pointservlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String point =request.getParameter("point");
Dao dao=new Dao();
String lineid="";
List<String> list=new ArrayList<>();
list=dao.pointselect(point);
for (String a:list) {
lineid=lineid+a+" , ";
}
request.setAttribute("lineid",lineid+"号线");
request.setAttribute("point",point);
request.getRequestDispatcher("point.jsp").forward(request,resp);
}
}
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/line")
public class lineservlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
String line=request.getParameter("line");
String line1="";
Dao dao=new Dao();
List<position> list =dao.lineselect(line);
for (position point:list) {
//System.out.println(point.getPosition());
line1=line1+point.getPosition()+"-->";
request.setAttribute("line1",line1);
request.setAttribute("line",line+"号线");
}
request.getRequestDispatcher("line.jsp").forward(request,resp);
}
}
<%--<%–--%>
<%-- Created by IntelliJ IDEA.--%>
<%-- User: 29782--%>
<%-- Date: 2024/4/23--%>
<%-- Time: 17:07--%>
<%-- 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 method="post" action="line">--%>
<%-- <input type="text" name="line">--%>
<%-- <button>提交</button><br>--%>
<%-- <div>${line}</div>--%>
<%--</form>--%>
<%--</body>--%>
<%--</html>--%>
<%--
Created by IntelliJ IDEA.
User: 29782
Date: 2024/3/31
Time: 19:32
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo</title>
<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
<link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>
<form method="post" action="line">
<div class="layui-form">
<input type="text" name="line" placeholder="请输入地铁线的名称" class="layui-input">
<hr class="ws-space-16">
</div>
<div class="layui-btn-container">
<button type="submit" class="layui-btn">提交</button>
</div>
</form>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo</title>
<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
<link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>
<br>
<br>
<table class="layui-table">
<colgroup>
<col width="150">
<col width="150">
<col>
</colgroup>
<thead>
<tr>
<th>地铁号</th>
<th>路线</th>
</tr>
</thead>
<tbody>
<tr>
<td>${line}</td>
<td>${line1}</td>
</tr>
</tbody>
</table>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="layui/layui.js"></script>
</body>
</html>
<%--<%–--%>
<%-- Created by IntelliJ IDEA.--%>
<%-- User: 29782--%>
<%-- Date: 2024/4/24--%>
<%-- Time: 16:38--%>
<%-- 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 method="post" action="point">--%>
<%-- <input type="text" name="point">--%>
<%-- <button>提交</button><br>--%>
<%-- <div>${lineid}</div>--%>
<%--</form>--%>
<%--</body>--%>
<%--</html>--%>
<%--
<%--
Created by IntelliJ IDEA.
User: 29782
Date: 2024/3/31
Time: 19:32
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo</title>
<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
<link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>
<form method="post" action="point">
<div class="layui-form">
<input type="text" name="point" placeholder="请输入站点的名称" class="layui-input">
<hr class="ws-space-16">
</div>
<div class="layui-btn-container">
<button type="submit" class="layui-btn">提交</button>
</div>
</form>
<br>
<br>
<table class="layui-table">
<colgroup>
<col width="150">
<col width="150">
<col>
</colgroup>
<thead>
<tr>
<th>地铁站</th>
<th>地铁号</th>
</tr>
</thead>
<tbody>
<tr>
<td>${point}</td>
<td>${lineid}</td>
</tr>
</tbody>
</table>
<script src="layui/layui.js"></script>
</body>
</html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)