今日总结
学习时间1.5h
一个简易查询
package Main;标签:resp,req,5.23,void,import,servlet,javax From: https://www.cnblogs.com/tianpeisen/p/18250865
import Bean.SubwayBean;
import Dao.Sub;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
/**
*
* **/
@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() {
}
}