2024.4.8
所学时间:2小时
代码行数:81
博客园数:1篇
所学知识:今天我和张雨锟继续写个人作业,今天先读取线路的每个站点,首先读取数据库,利用空格截取站点信息,如果前面加了#了还要读取后面的线路,是哪个线路的交点,最后通过Servle调取到前端页面,通过测试,完成了操作。
package com.example.niumo67;
import com.example.niumo67.Subway.GetInfo;
import com.example.niumo67.ut.Find;
import com.example.niumo67.ut.StationQuery;
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.sql.SQLException;
import java.text.ParseException;
@WebServlet(name="SQServlet",value = "/SQ-servlet")
public class StationQueryServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) {
GetInfo getInfo = null;
try {
getInfo = GetInfo.getGetInfo();
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
try {
getInfo.subwayMap();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
String ud=request.getParameter("station");
try {
String stationn= StationQuery.SQ(ud);
request.setAttribute("stationn",stationn);
request.getRequestDispatcher("Station.jsp").forward(request,response);
} catch (ParseException e) {
throw new RuntimeException(e);
} catch (ServletException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}