• 12月17


    今天发布剩余的servlet

    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.SQLException;
    import java.util.List;

    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.fasterxml.jackson.databind.ObjectMapper;

    import bean.paper;
    import dao.dao;

    /**
    * Servlet implementation class getallpaper
    */
    @WebServlet("/getallpaper")
    public class getallpaper extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public getallpaper() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    dao p=new dao();
    PrintWriter out=response.getWriter();
    String json="{}";
    try {
    List<paper> list=p.getallpaper();
    ObjectMapper om=new ObjectMapper(); //需要导包jackson
    json=om.writeValueAsString(list);
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    out.println(json);
    out.flush();
    out.close();
    }

    /**
    * @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);
    }

    }

    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.SQLException;
    import java.util.List;

    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.fasterxml.jackson.databind.ObjectMapper;

    import bean.keyword;
    import bean.paper;
    import dao.dao;

    /**
    * Servlet implementation class wordcloud
    */
    @WebServlet("/wordcloud")
    public class wordcloud extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public wordcloud() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    dao p=new dao();
    String id=request.getParameter("id");
    String name=request.getParameter("name");
    String writer=request.getParameter("writer");
    String time=request.getParameter("time");
    String keywords=request.getParameter("keywords");

    PrintWriter out=response.getWriter();
    String json="{}";
    try {
    List<keyword> list=p.getkey(id,name,writer,time,keywords);
    ObjectMapper om=new ObjectMapper();
    json=om.writeValueAsString(list);
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    out.println(json);
    out.flush();
    out.close();
    }

    /**
    * @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);
    }

    }

  • 相关阅读:
    Python3 调用 Ansible2.x API
    Django——form组件和ModelForm
    Python super().__init__()测试及理解
    ORACLE迁移记录
    CentOS7安装zabbix5.0
    ORACLE LINUX 7.7 安装ORACLE 11.2.0.4.0 RAC
    Spring
    【Git】clone项目&push项目没反应,Cloning into...没下载
    样式不显示,静态资源路径错误
    日常Java练习题
  • 原文地址:https://www.cnblogs.com/ldy2396/p/15703548.html
Copyright © 2020-2023  润新知