zoukankan      html  css  js  c++  java
  • 2021.5.20

    今日学习进度:

      第一天  第二天 第三天  第四天  第五天 
    所花时间(小时) 5  6  3  5  
    代码量(行) 200  300  150  500  
    博客量(篇) 1  1  1  1  
    了解到的知识点 CSS伪元素  CSS导航栏1  CSS导航栏2  顶会热词分析3  

    增加lunwenBean.java

    package classes;
    
    public class lunwenBean {
        private String title;
        private String zhaiyao;
        private String zuozhe;
        private String lianjie;
        private String time;
        public lunwenBean(String title, String zhaiyao, String zuozhe, String lianjie, String time) {
            super();
            this.title = title;
            this.zhaiyao = zhaiyao;
            this.zuozhe = zuozhe;
            this.lianjie = lianjie;
            this.time = time;
        }
        public String getTitle() {
            return title;
        }
        public void setTitle(String title) {
            this.title = title;
        }
        public String getZhaiyao() {
            return zhaiyao;
        }
        public void setZhaiyao(String zhaiyao) {
            this.zhaiyao = zhaiyao;
        }
        public String getZuozhe() {
            return zuozhe;
        }
        public void setZuozhe(String zuozhe) {
            this.zuozhe = zuozhe;
        }
        public String getLianjie() {
            return lianjie;
        }
        public void setLianjie(String lianjie) {
            this.lianjie = lianjie;
        }
        public String getTime() {
            return time;
        }
        public void setTime(String time) {
            this.time = time;
        }
        
    }

    改进servlet.java:

    package classes;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    
    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 net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    
    /**
     * Servlet implementation class servlet
     */
    @WebServlet("/servlet")
    public class servlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
        Dao dao=new Dao();
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public servlet() {
            super();
            // TODO Auto-generated constructor stub
        }
        public void findlunwen(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException, SQLException {
            req.setCharacterEncoding("utf-8");
            String zhaiyao=req.getParameter("zhaiyao");
            String title=req.getParameter("title");
            String zuozhe = req.getParameter("zuozhe");
            List<lunwenBean> list = dao.getselectlunwen(zhaiyao,title,zuozhe);
            PrintWriter out = response.getWriter();
            JSONArray json=new JSONArray();
            for(int i=0;i<list.size();i++) {
                JSONObject ob=new JSONObject();
                ob.put("title", list.get(i).getTitle());
                ob.put("zuozhe", list.get(i).getZuozhe());
                ob.put("abstract", list.get(i).getZhaiyao());
                ob.put("time", list.get(i).getTime());
                ob.put("lianjie", list.get(i).getLianjie());
                json.add(ob);
            }
            //System.out.println("JSON"+json.toString());
            System.out.println("zongshu"+list.size());
            out.write(json.toString());
            
        }
        public void reci(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
            request.setCharacterEncoding("utf-8");
            Map<String, Integer>sortMap=Dao.getrc();
            JSONArray json =new JSONArray();
            int k=0;
            for (Map.Entry<String, Integer> entry : sortMap.entrySet()) 
            {
                JSONObject ob=new JSONObject();
                ob.put("name", entry.getKey());
                ob.put("value", entry.getValue());
                if(!(entry.getKey().equals("for")||entry.getKey().equals("and")||entry.getKey().equals("With")||entry.getKey().equals("of")||entry.getKey().equals("in")||entry.getKey().equals("From")||entry.getKey().equals("A")||entry.getKey().equals("to")||entry.getKey().equals("a")||entry.getKey().equals("the")||entry.getKey().equals("by")))
                {
                    json.add(ob);
                    k++;
                }
                if(k==10)
                    break;
            }
            System.out.println(json.toString());
            
            response.getWriter().write(json.toString());
        }
        public void aja(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
             PrintWriter out = response.getWriter();
             String name = request.getParameter("name").trim();
             String type="-1";
             try {
                 response.setCharacterEncoding("UTF-8");
                 response.setContentType("application/json; charset=utf-8");
    //             out.println("Success---llll");
                 out.append(type);
                 out.close();
             } catch (Exception e){
                 e.printStackTrace();
             }
             
         
        }
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            request.setCharacterEncoding("utf-8");
            String method=request.getParameter("method");
            if(method.equals("findlunwen")) {
                 try {
                     findlunwen(request,response);
             } catch (ServletException e) {
                     e.printStackTrace();
             } catch (IOException e) {
                     e.printStackTrace();
             } catch (SQLException e) {
                 e.printStackTrace();
         }
                 
            }
            else if(method.equals("aja")) {
                try {
                    aja(request,response);
            } catch (ServletException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            } catch (SQLException e) {
                    e.printStackTrace();
            }
            }
            else if(method.equals("reci")) {
                try {
                    reci(request,response);
            } catch (ServletException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            } catch (SQLException 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);
        }
    
    }

        还是运行不出来,明天继续。

  • 相关阅读:
    163邮箱手机版怎么登录?原来邮箱无需账号就能登陆也有技巧!
    Failed to register dubbo://192.168.137.1:20880/com.youfan.service.SayHelloService?anyhost=true&appli
    Linux下安装zookeeper
    ZooKeeper 启动报错ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/
    Github的工作流程
    Git+Github 的工作流程
    如何通过github pages自定义CSDN、简书、博客园等平台域名
    remote: Repository not found. fatal: repository 'https://github.com/AlbertYang666/AlbertYang666.gith
    在maven项目中配置数据库连接池Druid
    在Spring+maven项目中配置数据库连接池Druid
  • 原文地址:https://www.cnblogs.com/marr/p/14905855.html
Copyright © 2011-2022 走看看