4.12 重写团队作业1
最简单的就是三个数据的java文件,只需要写出对应的属性即可,还有连接数据库的DBUtil文件。
写出了一些功能,可以返回一些数据
看Servlet的代码
package classes.com.servlet; import java.io.IOException; 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 javax.servlet.http.HttpSession; import classes.com.bean.dao; /** * Servlet implementation class DataServlet */ @WebServlet("/DataServlet") public class DataServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DataServlet() { super(); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/text;charset=UTF-8"); String method = request.getParameter("method"); System.out.println("DataServlet"); if(method.equals("c1")) { try { System.out.println("c1"); dao dao = new dao(); String get_c1_data = dao.get_c1_data(); response.getWriter().write(get_c1_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("c2")) { try { dao dao = new dao(); String get_c2_data = dao.get_c2_data(); response.getWriter().write(get_c2_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("c3")) { try { dao dao = new dao(); String get_c3_data = dao.get_c3_data(); response.getWriter().write(get_c3_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("l1")) { try { dao dao = new dao(); String get_l1_data = dao.get_l1_data(); response.getWriter().write(get_l1_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("l2")) { try { dao dao = new dao(); String get_l2_data = dao.get_l2_data(); response.getWriter().write(get_l2_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("r1")) { try { dao dao = new dao(); String get_r1_data = dao.get_r1_data(); response.getWriter().write(get_r1_data); } catch (Exception e) { e.printStackTrace(); } }else if(method.equals("r2")) { try { dao dao = new dao(); String get_r2_data = dao.get_r2_data(); response.getWriter().write(get_r2_data); } catch (Exception e) { e.printStackTrace(); } } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }