昨天偷了懒
今天发布剩余的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);
}
}