servlet与前端完美连接的代码
package com.servlet; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; 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 com.bean.Line; import com.dao.UserDao; import com.service.UserService; /** * Servlet implementation class servlet */ @WebServlet("rvlet") public class servlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public servlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); //1 response.setContentType("textml;charset=utf-8"); //2 response.setCharacterEncoding("utf-8"); //3 UserDao dao = new UserDao(); Line line = new Line(); ArrayList<String> array = new ArrayList<String>(); String startstopname=request.getParameter("startstopname"); String endstopname=request.getParameter("endstopname"); line.setStartstopname(startstopname); line.setEndstopname(endstopname); try { int x=dao.CheckAll(line); System.out.println("实际上传过来的值是"+x); if(x==1) { array=dao.Connectonlyoneline(line); } else if(x==2) { array=dao.Connecttwoline(line); } else if(x==3){ array=dao.Connectthreeline(line); } else { request.setAttribute("message", "请输入正确的站名!"); request.getRequestDispatcher("/Query.jsp").forward(request, response); return; } //array=dao.Connectthreeline(line); request.setAttribute("stop", array); /* if(array.equals(null)) { }*/ } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { request.getRequestDispatcher("/result.jsp").forward(request, response); } } }
标签:dao,request,查询,地铁,进度,import,line,servlet,response From: https://www.cnblogs.com/psh888/p/17228257.html