4.9

@WebServlet("/SubwayMain")
public class SubwayMain extends HttpServlet {
@Override
public void init() throws ServletException {
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

resp.setContentType("text/html;charset=UTF-8");
PrintWriter out = resp.getWriter();

String start = new String(req.getParameter("start_station").getBytes("ISO8859-1"),"UTF-8");
String end = new String(req.getParameter("end_station").getBytes("ISO8859-1"),"UTF-8");

try {
Sub sub = new Sub();
ArrayList<SubwayBean> arr = sub.ArrayTransferStation(start,end);
if (arr!=null){
req.setAttribute("routeMain", arr);
req.getRequestDispatcher("/bestresult.jsp").forward(req, resp);
}else {
req.getRequestDispatcher("/fail.jsp").forward(req, resp);
}

}catch (Exception e){
e.printStackTrace();
}finally {

}

}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
@Override
public void destroy() {

}
}
@WebServlet("/SubwayStation")
public class SubwayStation extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

resp.setContentType("text/html;charset=UTF-8");
PrintWriter out = resp.getWriter();

String na = req.getParameter("name");

DB db = new DB();
Sub sub = new Sub();

String line = sub.LineStation(na);
if (line!=null){
req.setAttribute("routeStation", line);
req.getRequestDispatcher("/nameresult.jsp").forward(req, resp);
}else {
req.getRequestDispatcher("/fail.jsp").forward(req, resp);
}


}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
@Override
public void init() throws ServletException {
}
@Override
public void destroy() {

}
}
posted @ 2024-04-19 22:52  涨涨涨张  阅读(4)  评论(0编辑  收藏  举报