文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>AddOrDelNumberServlet

AddOrDelNumberServlet

时间:2010-07-06  来源:mozhx

package com.newspager.servlet; import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.newspager.dao.AddNumberDAO;
import com.newspager.dao.TempNumberDAO;
import com.newspager.dao.impl.AddNumberDAOImpl;
import com.newspager.dao.impl.TempNumberImpl;
import com.newspager.model.AddNumber;
import com.newspager.model.TempNumber;
public class AddOrDelNumberServlet extends HttpServlet {     /**
  *
  */
 private static final long serialVersionUID = 1L;
 protected void processRequest (HttpServletRequest request,
            HttpServletResponse response, String method)
            throws ServletException, IOException {
  //System.out.println("servlet222");
                //把响应内容类型设置为 text/xml
                response.setContentType("text/xml");
                response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
                response.setHeader("Pragma","no-cache"); //HTTP 1.0
                response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
                int userId = 0;
                int pagerId = 0;
                int num = 0;
                String pweek;
                //得到用户参数值
                String uid = "";
                String pgid = "";
                String amount = "";
               
                 uid = request.getParameter("userId");
                 pgid = request.getParameter("pagerId");
                 amount = request.getParameter("amount");
                 pweek = request.getParameter("pweek");
               
                if(amount != null && amount.trim() != ""){
                 num = Integer.parseInt(amount);
                }
                if(uid != null && uid.trim() != ""){
                 userId = Integer.parseInt(uid);
                }
                if(pgid != null && pgid.trim() != ""){
                 pagerId = Integer.parseInt(pgid);
                }
               
                TempNumber tempNumber = new TempNumber();
                tempNumber.setAmount(num);
                tempNumber.setUserId(userId);
                tempNumber.setPagerId(pagerId);
               
               
                TempNumberDAO tnDAO = new TempNumberImpl();
                //写回浏览器
                PrintWriter out = response.getWriter();
                /**
                 * 如果接收到的参数num值等于0,就删除该报纸数量记录
                 * 否则,如果存在该报纸数量记录,就更新数量
                 * 否则,就添加一条报纸数量记录
                 *
                 */
                if(num == 0){
                 tnDAO.delete(tempNumber);
                }else if(tnDAO.isExistPager(userId,pagerId)){
                 tnDAO.update(tempNumber);
                }else{
                 tnDAO.add(tempNumber);
                }
                AddNumberDAO andao = new AddNumberDAOImpl();
                AddNumber an = new AddNumber();
                an.setUserId(userId);
                an.setPagerId(pagerId);
                an.setPweek(pweek);
                //修改完成后,判断该报纸是否有加减数功能
                //如果有就刷新页面
                if(andao.isExistAddNumber(an)){
                 out.write("window.location.href=window.location.href;");
                }
               
                out.close();
            }
            protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                //Get主函数调用processRequest,完成Get方法的参数接受,返回的过程
                processRequest(request, response, "GET");
            }
            protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                //POST主函数调用processRequest,完成POST方法的参数接受,返回的过程
                processRequest(request, response, "POST");
            }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载