• 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);
        }
    
    }
  • 相关阅读:
    python远程连接服务器并查看服务器上的文件
    python中xe6x80xa5xe8xafx8a如何转为中文
    idea+testng+maven环境搭建
    Django restfulframework系列
    django-基于函数的视图与基于类的视图
    yaml结合数据驱动编写测试用例
    pycharm社区版找不到工具栏找不到Database的解决办法
    Content-Type 对照表
    ffmpeg C# 切第一秒的有图片
    Angular HttpClient POST 服务器(springboot)获取不到参数问题
  • 原文地址:https://www.cnblogs.com/cdl-sunshine/p/14907750.html
Copyright © 2020-2023  润新知