已经有了输入框,接下来要做的就是获得输入框的内容了。在设计模式上还是采用了javaweb的常用开发模式,即分成四层,Bean层,DB层,Dao层,servlet层。
在servlet获得前台传递的数据然后再用数据调用读取数据库的方法即可。
代码如下:
public void findlunwen(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
request.setCharacterEncoding("utf-8");
int tonum=Integer.parseInt(request.getParameter("sum"));
int realnum=Integer.parseInt(request.getParameter("realsum"));
List<demBean> findlist=new ArrayList<>();
demBean dbean=null;
dbean=new demBean("AND",request.getParameter("tiaojian"),request.getParameter("firinput"),request.getParameter("jingzhun"));
findlist.add(dbean);
for(int i=1;i<tonum;i++) {
if(request.getParameter("input"+i)!=""&&request.getParameter("input"+i)!=null) {
dbean=new demBean(request.getParameter("lianjie"+i),request.getParameter("tiaojian"+i),request.getParameter("input"+i),request.getParameter("jingdu"+i));
findlist.add(dbean);
}
}
System.out.println(realnum+"总数为"+findlist.size());
for(int i=0;i<findlist.size();i++) {
System.out.println(findlist.get(i).toString());
}
PrintWriter out = response.getWriter();
//String name = request.getParameter("name").trim();
List<lunwenBean> list = dao.getselectlunwen(findlist);
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("zhaiyao", 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());
}
使用这个方法就可以获得查询的论文的内容。