package com.action; import java.io.IOException; import java.util.List; import com.dao.ScripDAO; import com.model.ScripForm; import javax.servlet.ServletException; import javax.servlet.http.*; import com.tools.MyPagination; import com.tools.StringUtils; public class ScripAction extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; private ScripDAO scripDAO = null; //声明ScripDAO类的对象 private StringUtils su=new StringUtils(); //声明并实例化StringUtils类的对象 MyPagination pagination=null; //声明MyPagination类的对象 public ScripAction() { //构造方法 this.scripDAO = new ScripDAO(); //实例化ScripDAO类的对象 } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action =request.getParameter("action"); if("scripQuery".equals(action)){ scripQuery(request,response); //获取全部的许愿字条 }else if("scripAdd".equals(action)){ scripAdd(request,response); //保存许愿字条信息 }else if("addHoldout".equals(action)){ holdoutAdd(request,response); //添加支持 }else if("scripList".equals(action)){ scripList(request,response); //显示字条列表 }else if("scrollScrip".equals(action)){ scrollScrip(request,response); //最新字条滚动显示 }else{ request.setAttribute("error","操作失败!"); request.getRequestDispatcher("error.jsp") .forward(request, response); //转到错误提示页 } } public void scripQuery(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("scripList",scripDAO.query(null)); //查询字条信息 request.getRequestDispatcher("wishingWall.jsp") .forward(request, response); } public void scripAdd(HttpServletRequest request, HttpServletResponse response) { ScripForm scripForm=new ScripForm(); String wishMan=su.StringtoSql(request.getParameter("wishMan")); //祝福对象 String wellWisher=su.StringtoSql(request.getParameter("wellWisher")); //祝福者 String content=su.StringtoSql(request.getParameter("content")); //字条内容 if(!"".equals(wishMan)){ scripForm.setWishMan(wishMan); if(!"".equals(wellWisher)){ scripForm.setWellWisher(wellWisher); if(!"".equals(wellWisher)){ scripForm.setContent(content);//设置字条内容 scripForm.setFace(Integer.parseInt(request.getParameter("face")));//设置心情图案 scripForm.setColor(Integer.parseInt(request.getParameter("color"))); //设置字条颜色 String rtn=scripDAO.insert(scripForm); //保存字条信息 request.setAttribute("returnValue",rtn); }else{ request.setAttribute("returnValue","请输入字条内容!"); //保存提示信息 } }else{ String rtn=scripDAO.insert(scripForm); //保存字条信息 request.setAttribute("returnValue","请输入祝福者!"); } }else{ request.setAttribute("returnValue","请输入祝福对象!"); } System.out.println("祝福对象:"+scripForm.getWishMan()+"祝福者:"+scripForm.getWellWisher()+"字条颜色:"+scripForm.getColor()+"心情图案:"+scripForm.getFace()+"字条内容:"+scripForm.getContent()); try { request.getRequestDispatcher("scripAdd_ok.jsp").forward(request, response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void holdoutAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id=Integer.parseInt(request.getParameter("scripId")); //获传递的字条ID号 String hits=scripDAO.holdoutAdd(id); //将指定的字条的人气数加1 request.setAttribute("hits", hits); //保存新的单击数 request.getRequestDispatcher("holdoutAdd.jsp") .forward(request, response); } //查找字条列表 public void scripList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringUtils su=new StringUtils(); String strPage=(String)request.getParameter("Page"); String f = request.getParameter("f"); // 获取查询字段 String key = su.StringtoSql(request.getParameter("key")); // 获取查询关键字 String condition=""; if(("".equals(f) ||null==f) || ("all".equals(f) && "".equals(key))){ condition="ORDER BY sendTime DESC"; }else if("all".equals(f) && !"".equals(key)){ condition="WHERE wishMan like '%"+key+"%' OR wellWisher like '%"+key+"%' OR content like '%"+key+"%' ORDER BY sendTime DESC"; }else{ condition="WHERE "+f+" like '%"+key+"%' ORDER BY sendTime DESC"; } System.out.println("条件:"+condition); int Page=1; List list=null; if(strPage==null){ pagination=new MyPagination(); list=scripDAO.query(condition); //获取字条信息 int pagesize=5; //指定每页显示的记录数 list=pagination.getInitPage(list,Page,pagesize); //初始化分页信息 request.getSession().setAttribute("pagination",pagination); }else{ pagination=(MyPagination)request.getSession().getAttribute("pagination"); Page=pagination.getPage(strPage); list=pagination.getAppointPage(Page); //获取指定页数据 } request.setAttribute("scripList1",list); //保存当前页的字条信息 request.setAttribute("Page",Page); //保存的当前页码 request.setAttribute("f", f); request.setAttribute("key", key); request.getRequestDispatcher("scripList.jsp") .forward(request, response); } public void scrollScrip(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("scrollScrip",scripDAO.queryTop()); //查询最新的10条字条信息 request.getRequestDispatcher("scrollScrip_ok.jsp") .forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } }
最近下载更多
liu2022 LV14
2022年7月31日
wanglinddad LV55
2022年6月7日
Start1 LV15
2021年10月30日
夏至 LV3
2021年6月9日
是菲菲菲啦啦 LV3
2021年3月23日
159878 LV2
2020年11月26日
ExamplesDYC LV13
2020年11月22日
Snly小怪兽 LV4
2020年5月17日
Merlin12345 LV3
2020年3月25日
happy1231 LV7
2020年3月13日