package com.jy.web;
import com.jy.pojo.TotalStation;
import com.jy.service.Service;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
@WebServlet("/ResearchServlet")
public class ResearchServlet extends HttpServlet {
private Service service=new Service();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String Method=request.getParameter("Method");
if(Method.equals("XLCX"))
{
String routine=request.getParameter("routine");
List <TotalStation> totalStations1=service.research1(routine);
request.setAttribute("totalStations1", totalStations1);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else if(Method.equals("ZDCX"))
{
String station=request.getParameter("station");
List <TotalStation> totalStations2=service.research2(station);
System.out.println(totalStations2);
request.setAttribute("totalStations2", totalStations2);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else if(Method.equals("SECX"))
{
String routine1=request.getParameter("station1");
String routine2=request.getParameter("station2");
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
1、数据库设计:
total_station
id; 序号
routine; 线路
sta_routine; 第几站
station; 站名
页面设计
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>地铁站查询</title>
</head>
<style type="text/css">
button{
color: gold;
background-color: mediumaquamarine;
text-align: center;
font-size:20px;
height: 35px;
width: 10%;
margin-left:45%;
margin-bottom: 50px;
}
h1{
text-align: center;
width: 500px;
margin: 50px auto;
}
h3{
text-align: center;
width: 500px;
margin: 10px auto;
}
table{
text-align: center;
margin-left:40%;
}
</style>
<body text="#ffe4c4" bgcolor="#fff0f5" background="img.png">
<form action="ResearchServlet" method="post">
<h1>线路查询</h1>
<input type="hidden" name="Method" value="XLCX"><br>
<h3>请输入线路号:<input type="text" name="routine"></h3><br>
<button type="submit">查询</button>
<table border="0" cellspacing="10" width="20%" >
<c:forEach items="${totalStations1}" var="totalStation1" varStatus="id1">
<tr align="center">
<td>${totalStation1.getSta_routine()}</td>
<td>${totalStation1.getStation()}</td>
</tr>
</c:forEach>
</table>
</form>
<form action="ResearchServlet" method="post">
<h1>站点查询</h1>
<input type="hidden" name="Method" value="ZDCX"><br>
<h3>请输入站点号:<input type="text" name="station"></h3><br>
<button type="submit">查询</button>
<table border="0" cellspacing="10" width="20%" >
<c:forEach items="${totalStations2}" var="totalStation2" varStatus="id2">
<tr align="center">
<td>${id2.count}</td>
<td>${totalStation2.getRoutine()}</td>
</tr>
</c:forEach>
</table>
</form>
<form action="ResearchServlet" method="post">
<h1>起点-终点查询</h1>
<input type="hidden" name="Method" value="SECX"><br>
<h3>请输入起点:<input type="text" name="station1"></h3><br>
<h3>请输入终点:<input type="text" name="station2"></h3><br>
<button type="submit">查询</button>
</form>
</body>
</html>