jtahstu的博客

root@jtahstu.com   Github   英文博客  

最新碎语:以后没事写写小的知识点吧

您的位置:jtahstu的博客 >笔记> 大三下软件项目开发实训第九天 - 物流管理系统v3.0

大三下软件项目开发实训第九天 - 物流管理系统v3.0

分页笔记

关键字:上一页,下一页,首页,末页,总页数,总记录数,当前页数
        当前显示记录条数。
CurrentPage:当前页数
CurrentSize:当前显示记录条数。
当前显示记录数从第几条开始=(CurrentPage-1)*CurrentSize
分页功能:
  第一步:子dao支持
   public List<Kehudangan> spitPage(int CurrentPage,int CurrentSize){
       String sql="SELECT * FROM kehudangan LIMIT  "+(CurrentPage-1)*CurrentSize+","+CurrentSize+"";
       return super.query(sql);
      }
第二步:改造serlvet,show.do
String CurrentPage=request.getParameter("CurrentPage");
  String CurrentSize=request.getParameter("CurrentSize");
  int currentp=1;
  int currents=3;
  if(CurrentSize==null||CurrentSize==null){
   currentp=1;
   currents=3;
  }else{
   //将String类型的数据转化成整形。
   currentp=Integer.parseInt(CurrentPage);
   currents=Integer.parseInt(CurrentSize);
  }
  //查询客户档案所有信息
  List<Kehudangan> list=new KehudanganDAO().spitPage(currentp, currents);
  //保存数据
  request.setAttribute("khlist", list);
  System.out.println(list.size());
  request.getRequestDispatcher("kehudangan.jsp").forward(request, response);
      
  第三步:改造kehudangan.jsp页面 
     <a href="show.do?CurrentPage=<%=request.getAttribute("CurrentPage") %>&CurrentSize=<%=request.getAttribute("CurrentSize")%>">下一页</a>
  第四步:问题:
      程序判断用户点击的是上一页还是下一页啊。
      <a href="show.do?flag=1&CurrentPage=<%=request.getAttribute("CurrentPage") %>&CurrentSize=<%=request.getAttribute("CurrentSize")%>">上一页</a>
  第五步;改造show.do
     String CurrentPage=request.getParameter("CurrentPage");
  String CurrentSize=request.getParameter("CurrentSize");
  String flag=request.getParameter("flag");
  List<Kehudangan> list=new ArrayList<Kehudangan>();
  int currentp=1;
  int currents=3;
  if(flag==null){
   if(CurrentSize==null||CurrentSize==null){
    currentp=1;
    currents=3;
    list=new KehudanganDAO().spitPage(currentp, currents);
   }else{
    //将String类型的数据转化成整形。
   }
  }else{
   //判断是1还是0
   if(flag.equals("1")){
    currentp=Integer.parseInt(CurrentPage);
    currents=Integer.parseInt(CurrentSize);
    //查询客户档案所有信息
    list=new KehudanganDAO().spitPage(currentp, currents);
    //先查询当前页,之后才将当前页++,或者--
    currentp--;
    currents=3;
   }
   if(flag.equals("0")){
    currentp=Integer.parseInt(CurrentPage);
    currents=Integer.parseInt(CurrentSize);
    //查询客户档案所有信息
    currentp++;
    list=new KehudanganDAO().spitPage(currentp, currents);
    currents=3;
   }
  }
  //保存数据
  request.setAttribute("khlist", list);
  request.setAttribute("CurrentPage", currentp);
  request.setAttribute("CurrentSize", currents);
  System.out.println(list.size());
  request.getRequestDispatcher("kehudangan.jsp").forward(request, response);
   第六步:求总页数,子dao支持

kehudangan.jsp

<%@page import="com.it.bean.Kehudangan"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'kehudangan.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
 //表格隔行变色
      $(function(){
        $("#tb1 tr:odd").css("background-color","#eeeeee");
        $("#tb1 tr:even").css("background-color","white");
        $("#tr1").css("background-color","#6795b4");
      });
      //鼠标移到行上,行变色
     $(function(){
         $("#tb1 tr").bind("mousemove",function(){
         $(this).css("background-color","#6795b4");
         $("#tr1").css("background-color","#6795b4");
       });
         $("#tb1 tr").bind("mouseout",function(){
         $("#tb1 tr:odd").css("background-color","#eeeeee");
         $("#tb1 tr:even").css("background-color","white");
         $("#tr1").css("background-color","#6795b4");
       });
       //鼠标移动到超链接上,超链接变色
       $("a").bind("mousemove",function(){
           $(this).css("color","red");
         }); 
       //鼠标离开超链接上,超链接恢复颜色
       $("a").bind("mouseout",function(){
           $(this).css("color","#1b8ff2");
         }); 
        $("#upd").bind(); 
       });
       function add(){
         $.ajax({
            type:"post",
            url:"add.do",
            cache:false,
            data:$("#form1").serialize(),
            success:function(){
            }
         });
       }
       function jiazai(id){
          $.ajax({
             type:"post",
             url:"jiazai.do",
             cache:false,
             data:{"kh_bh":id},
             success:function(msg){
                //将json字符串转换成了数组
                eval("kehu="+msg);
                var bh=kehu[0].kh_bh;
                var bm=kehu[0].kh_bm;
                var mc=kehu[0].kh_mc;
                var jc=kehu[0].kh_jc;
                var dh=kehu[0].kh_dh;
                var dz=kehu[0].kh_dz;
                var lxr=kehu[0].kh_lxr;
                var email=kehu[0].kh_email;
                var cz=kehu[0].kh_cz;
                //将值赋给文本框
                $("#kh_bh").val(bh);
                $("#kh_bm").val(bm);
                $("#kh_mc").val(mc);
                $("#kh_jc").val(jc);
                $("#kh_dh").val(dh);
                $("#kh_dz").val(dz);
                $("#kh_lxr").val(lxr);
                $("#kh_email").val(email);
                $("#kh_cz").val(cz);
            }
          });
       }
       function search(){
       /* alert($("#kh_mc").val());*/
           $.ajax({
              type:"post",
              url:"search.do",
              cache:false,
              data:{"kh_mc":$("#kh_mc1").val()},
              success:function(msg){
                 //将json字符串转换成了数组
                 eval("kehu="+msg);
                 var bh=kehu[0].kh_bh;
                 var bm=kehu[0].kh_bm;
                 var mc=kehu[0].kh_mc;
                 var jc=kehu[0].kh_jc;
                 var dh=kehu[0].kh_dh;
                 var dz=kehu[0].kh_dz;
                 var lxr=kehu[0].kh_lxr;
                 var email=kehu[0].kh_email;
                 var cz=kehu[0].kh_cz;
                 //将值赋给文本框
                 $("#kh_bh").val(bh);
                 $("#kh_bm").val(bm);
                 $("#kh_mc").val(mc);
                 $("#kh_jc").val(jc);
                 $("#kh_dh").val(dh);
                 $("#kh_dz").val(dz);
                 $("#kh_lxr").val(lxr);
                 $("#kh_email").val(email);
                 $("#kh_cz").val(cz);
                 $("#mc").html("已帮您查找到用户名称叫<span style='color:red'>"+mc+"</span>的用户");
             }
           });
        }
       function upd(){
       $.ajax({
            type:"post",
            url:"upd.do",
            cache:false,
            data:$("#form1").serialize(),
            success:function(msg){
               if(msg==1){
                 alert("====恭喜哥,修改成功!====");
               }
            }
         });}
 </script>
<style type="text/css">
body {
 margin: 0px;
}
#tb1 {
 border: #666666;
 width: 1175px;
 border: 1px solid #464646;
 border-collapse: collapse;
}
#tb2 {
 width: 918px;
 border: 1px;
}
#tb1 tr td {
 border: 1px;
 border-color: #464646;
 border-collapse: collapse;
 border-style: solid;
}
#tr1 {
 background-color: #6795b4;
 height: 30px;
 font-size: 18px;
}
#tr1 td {
 color: #FFFFFF;
}
#tr2 {
 background: #eeeeee;
 text-align: center;
}
#tr1 td {
 color: #FFFFFF;
}
#tr2 {
 background: #eeeeee;
 text-align: center;
}
a {
 text-decoration: none;
}
</style>
</style>
</head>
<body>
<%
   List<Kehudangan> list=(List<Kehudangan>)request.getAttribute("khlist");
 %>
 <img alt="" src="images/righttopbanner1.jpg" style="margin-left:170px">
 <table id="tb1" style="margin-left:250px">
  <tr id="tr1">
   <td height="25" colspan="10"><div align="center">客户档案</div>
   </td>
  </tr>
  <tr id="tr2">
   <td>客户编号</td>
   <td>客户编码</td>
   <td>客户名称</td>
   <td>客户简称</td>
   <td>客户电话</td>
   <td>客户地址</td>
   <td>客户联系人</td>
   <td>客户E-Mail</td>
   <td>客户传真</td>
   <td>操作</td>
  </tr>
  <%for(int i=0;i<list.size();i++){ %>
   <tr>
    <td><%=list.get(i).getKh_bh() %></td>
    <td><%=list.get(i).getKh_bm() %></td>
    <td><%=list.get(i).getKh_mc() %></td>
    <td><%=list.get(i).getKh_jc() %></td>
    <td><%=list.get(i).getKh_dh() %></td>
    <td><%=list.get(i).getKh_dz() %></td>
    <td><%=list.get(i).getKh_lxr() %></td>
    <td><%=list.get(i).getKh_email() %></td>
    <td><%=list.get(i).getKh_cz() %></td>
     <td>
        <a href="del.do?kh_bh=<%=list.get(i).getKh_bh() %>"><img title="删除" src="image/delete.png"></a>
        <img title="修改" src="image/upd.png" onclick="jiazai('<%=list.get(i).getKh_bh() %>')">
     </td> 
   </tr>
   <%} %>
 </table>
 <p style="text-align:center">
 <a href="show.do">首页</a>
 <a href="show.do?flag=1&CurrentPage=<%=request.getAttribute("CurrentPage") %>&CurrentSize=<%=request.getAttribute("CurrentSize")%>">上一页</a>
 <a href="show.do?flag=0&CurrentPage=<%=request.getAttribute("CurrentPage") %>&CurrentSize=<%=request.getAttribute("CurrentSize")%>">下一页</a>
 <a href="show.do?flag=1&CurrentPage=<%=request.getAttribute("last") %>&CurrentSize=<%=request.getAttribute("CurrentSize")%>">末页</a>
 <%=request.getAttribute("CurrentPage") %>/<%=request.getAttribute("total") %>
 </p>
 <form id="form1" > 
  <table id="tb2" align="center">
   <tr>
    <td width="131"><div align="right">客户编号:</div>
    </td>
    <td width="180"><input type="text" name="kh_bh" id="kh_bh" />
    </td>
    <td width="93"><div align="right">客户编码:</div>
    </td>
    <td width="182"><input type="text" name="kh_bm" id="kh_bm" />
    </td>
    <td width="113"><div align="right">客户名称:</div>
    </td>
    <td width="179"><input type="text" name="kh_mc" id="kh_mc" />
    </td>
   </tr>
   <tr>
    <td><div align="right">客户简称:</div>
    </td>
    <td><input type="text" name="kh_jc" id="kh_jc" />
    </td>
    <td><div align="right">客户电话:</div>
    </td>
    <td><input type="text" name="kh_dh" id="kh_dh" />
    </td>
    <td><div align="right">客户地址:</div>
    </td>
    <td><input type="text" name="kh_dz" id="kh_dz" />
    </td>
   </tr>
   <tr>
    <td><div align="right">客户联系人:</div>
    </td>
    <td><input type="text" name="kh_lxr" id="kh_lxr" />
    </td>
    <td><div align="right">客户邮箱:</div>
    </td>
    <td><input type="text" name="kh_email" id="kh_email" />
    </td>
    <td><div align="right">客户传真:</div>
    </td>
    <td><input type="text" name="kh_cz" id="kh_cz" />
    </td>
   </tr>
   <tr>
    <td height="10"></td>
   </tr>
   <tr align="center">
    <td colspan="6">
        <input type="submit" class="right_button01"  onclick="add()" value="添加" name="btt"/>
     <input type="submit" class="right_button01" value="修改" onclick="upd()" name="btt" />
        <input type="reset" class="rigth_button01" value="重置" name="btt" />
    </td>
   </tr>
  </table>
         </form>
        <div style="margin-left:680px"> <input type="text" name="kh_mc" id="kh_mc1" />
         <input type="submit" class="right_button01" onclick="search()" value="查询" name="btt" /></div>
         <br>
         <p id="mc" align="center"></p> 
</body>
</html>

updpwd.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>修改密码</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">    
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
 <script type="text/javascript">
    function xg(){
        //得到新密码的值
      var newpwd=$("#newpwd").val();
        //得到确认密码的值
      var qrpwd=$("#qrpwd").val();
      var username=$("#username").val();
      var userpwd=$("#userpwd").val();
        if(newpwd==qrpwd){
           $.ajax({
                 type:"post",
                 url:"updpwd.do",
                 cache:false,
                  data:{"username":username,"userpwd":userpwd,"newpwd":newpwd},
                  success:function(msg){ 
                  /*alert("===2===="+msg);*/
                     if(msg==1){
                     /*alert("===1===");
                        var url="mesage.jsp";
                        window.location=url;*/
                      $("#mesg").text("nice,密码修改成功").css("color","green");
                     }
                   }
         });
        }
        else{
          $("#mesg").text("两次密码不一致").css("color","red");
        }
    }    
 </script>
<style type="text/css">
   #yuandao{
     width:100%;
     height:50px;
  background-color:#666666;
  font-size:30px;
  color:#FFFFFF;
  text-align:center;
  line-height:50px;
   }
   #content{
     width:800px;
  height:400px;
  border-top:#0099FF solid 2px;
  border-left:#0099FF solid 1px;
  border-right:#0099FF solid 1px;
  border-bottom:#0099FF solid 1px;
  font-size:18px;
  margin:0 auto;
   }
   #xgmm{
   font-size:20px;
   padding-left:5%;
   }
   hr{
   border:#00CCCC solid 1px;
   }
   #username{
   width:260px;
   height:30px;
   }
   #userpwd{
   width:260px;
   height:30px;
   }
   #newpwd{
   width:260px;
   height:30px;
   }
   #qrpwd{
   width:260px;
   height:30px;
   }
   #content div{
       padding-left:30%;
    padding-top:5%;
   }
   input{
   margin-top:20px;
   }
   #xiugai{
   width:50px;
   height:33px;
   margin-left:25%;
 /*   background-image:url(image/save.png); */
   }
   #chongzhi{
   width:50px;
   height:33px;
   margin-left:30px;
   }
</style>
  </head>
  <body>
    <div id="yuandao">
     <span>德玛西亚</span>
  </div>
  <br/>
  <span id="xgmm">修改密码</span>
  <hr/>
  <div id="content">
  <div>
              用&nbsp;户&nbsp;名:<input type="text" id="username"  name="user_id"/><br/>
             老&nbsp;密&nbsp;码:<input type="password"  id="userpwd"   name="user_pwd"/><br/>
             新&nbsp;密&nbsp;码:<input type="password"  id="newpwd"    name="newpwd"/><br/>
             确认密码:<input type="password"  id="qrpwd"    name="qrpwd"/><span id="mesg"></span><br/>
             <input id="xiugai" type="submit" onclick="xg()" value="修改"/>
             <input id="chongzhi" type="reset" value="重置"/>
 </div>
  </div>
  </body>
</html>

kehudanganDAO.java

package com.it.dao;
import java.util.List;
import com.it.bean.Kehudangan;
public class KehudanganDAO extends BaseDAO<Kehudangan> {
 public List<Kehudangan> reqKehudangan() {
  String sql = "select * from kehudangan";
  return super.query(sql);
 }
 /**
  * 删除客户档案信息
  */
 public void delKehudangan(String kh_bh) {
  String sql = "delete from kehudangan where kh_bh='" + kh_bh + "'";
  super.update(sql);
 }
 /**
  * 添加客户档案信息
  */
 public void insertKehudangan(Kehudangan kh) {
  String sql = "insert into kehudangan values('" + kh.getKh_bh() + "','"
    + kh.getKh_bm() + "','" + kh.getKh_mc() + "','" + kh.getKh_jc()
    + "','" + kh.getKh_dh() + "','" + kh.getKh_dz() + "','"
    + kh.getKh_lxr() + "','" + kh.getKh_email() + "','"
    + kh.getKh_cz() + "')";
  super.update(sql);
 }
 /**
  * 修改用户信息
  */
 public void updKehudangan(Kehudangan kh) {
  String sql = "update kehudangan set kh_bm='" + kh.getKh_bm()
    + "',kh_mc='" + kh.getKh_mc() + "',kh_jc='" + kh.getKh_jc()
    + "',kh_dh='" + kh.getKh_dh() + "',kh_dz='" + kh.getKh_dz()
    + "',kh_lxr='" + kh.getKh_lxr() + "',kh_email='"
    + kh.getKh_email() + "',kh_cz='" + kh.getKh_cz()
    + "' where kh_bh='" + kh.getKh_bh() + "'";
  System.out.println("=====update=======" + sql);
  super.update(sql);
 }
 /**
  * 按照用户编号查询用户信息
  */
 public List<Kehudangan> findByBh(String id) {
  String sql = "select * from kehudangan where kh_bh='" + id + "'";
  return super.query(sql);
 }
 public List<Kehudangan> findByMc(String mc) {
  String sql = "select * from kehudangan where kh_mc='" + mc + "'";
  return super.query(sql);
 }
 /**
  * 分页语句
  */
 public List<Kehudangan> spitPage(int CurrentPage, int CurrentSize) {
  String sql = "SELECT * FROM kehudangan LIMIT  " + (CurrentPage - 1)
    * CurrentSize + "," + CurrentSize + "";
  return super.query(sql);
 }
 /**
  * 求总页数
  */
 public int totalPage(int CurrentSize) {
  int total = ((reqKehudangan().size() - 1) / CurrentSize) + 1;
  return total;
 }
 public void rs2list(List<Kehudangan> list) {
  try {
   while (rs.next()) {
    String kh_bh = rs.getString("kh_bh");
    String kh_bm = rs.getString("kh_bm");
    String kh_mc = rs.getString("kh_mc");
    String kh_jc = rs.getString("kh_jc");
    String kh_dh = rs.getString("kh_dh");
    String kh_dz = rs.getString("kh_dz");
    String kh_lxr = rs.getString("kh_lxr");
    String kh_email = rs.getString("kh_email");
    String kh_cz = rs.getString("kh_cz");
    Kehudangan kehu = new Kehudangan(kh_bh, kh_bm, kh_mc, kh_jc,
      kh_dh, kh_dz, kh_lxr, kh_email, kh_cz);
    list.add(kehu);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

JiaZaiServlet.java

package com.it.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
import com.it.util.List2json2;
/**
 * Servlet implementation class JiazaiServlet
 */
public class JiaZaiServlet extends HttpServlet {
 /**
  * @see HttpServlet#HttpServlet()
  */
 public JiaZaiServlet() {
  super();
  // TODO Auto-generated constructor stub
 }
 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doPost(request, response);
 }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=utf-8");
  String bh = request.getParameter("kh_bh");
  List<Kehudangan> list = new KehudanganDAO().findByBh(bh);
  // System.out.println(list.size() + "1111111");
  String dataString = List2json2.obj2jsonArr(list);
  // System.out.println(dataString + "22222222222");
  response.getWriter().print(dataString);
 }
}

LoginServlet.java

package com.it.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.it.bean.UserInfo;
import com.it.dao.UserInfoDAO;
public class LoginServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public LoginServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  String user_id=request.getParameter("user_id");
  String user_pwd=request.getParameter("user_pwd");
  //调用子dao中的的登录方法
//  int flag=new UserInfoDAO().login(user_id, user_pwd);
  List<UserInfo> list=new UserInfoDAO().login1(user_id, user_pwd);
  if(list.size()>0){
   //登陆成功后,去主界面。
   //创建session对象,作用域----权限。
   HttpSession session=request.getSession();
   session.setAttribute("userinfo", list.get(0));
   response.sendRedirect("index.jsp");
  }else{
   //登陆失败之后,重新定向到登陆界面。
   HttpSession session=request.getSession();
   session.setAttribute("msg", "用户名或密码错误!");
   response.sendRedirect("login.jsp");
  }
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

SearchServlet.java

package com.it.servlet;
import java.io.IOException;
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.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
import com.it.util.List2json2;
/**
 * Servlet implementation class SearchServlet
 */
@WebServlet("/search.do")
public class SearchServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
 /**
  * @see HttpServlet#HttpServlet()
  */
 public SearchServlet() {
  super();
  // TODO Auto-generated constructor stub
 }
 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doPost(request, response);
 }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=utf-8");
  String mc = request.getParameter("kh_mc");
  List<Kehudangan> list = new KehudanganDAO().findByMc(mc);
  // System.out.println(list.size() + "1111111");
  String dataString = List2json2.obj2jsonArr(list);
  // System.out.println(dataString + "22222222222");
  response.getWriter().print(dataString);
 }
}

ShowServlet.java

package com.it.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
public class ShowServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public ShowServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request
  *            the request send by the client to the server
  * @param response
  *            the response send by the server to the client
  * @throws ServletException
  *             if an error occurred
  * @throws IOException
  *             if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to
  * post.
  * 
  * @param request
  *            the request send by the client to the server
  * @param response
  *            the response send by the server to the client
  * @throws ServletException
  *             if an error occurred
  * @throws IOException
  *             if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  String CurrentPage = request.getParameter("CurrentPage");
  String CurrentSize = request.getParameter("CurrentSize");
  String flag = request.getParameter("flag");
  List<Kehudangan> list = new ArrayList<Kehudangan>();
  int currentp = 1;
  int currents = 3;
  int total = new KehudanganDAO().totalPage(currents);
  int last = total + 1;
  if (flag == null) {
   if (CurrentPage == null && CurrentSize == null) {
    currentp = 1;
    currents = 3;
    list = new KehudanganDAO().spitPage(currentp, currents);
   } else {
   }
  } else {
   // 判断是1还是0
   if (flag.equals("1")) {
    currentp = Integer.parseInt(CurrentPage);
    currents = Integer.parseInt(CurrentSize);
    currentp--;
    // 查询客户档案所有信息
    if (currentp < 1) {
     currentp = 1;
    }
    list = new KehudanganDAO().spitPage(currentp, currents);
    // 先查询当前页,之后才将当前页++,或者--
    currents = 3;
   }
   if (flag.equals("0")) {
    currentp = Integer.parseInt(CurrentPage);
    currents = Integer.parseInt(CurrentSize);
    // 查询客户档案所有信息
    currentp++;
    if (currentp > total) {
     currentp = total;
    }
    list = new KehudanganDAO().spitPage(currentp, currents);
    currents = 3;
   }
  }
  // 保存数据
  request.setAttribute("khlist", list);
  request.setAttribute("CurrentPage", currentp);
  request.setAttribute("CurrentSize", currents);
  request.setAttribute("total", total);
  request.setAttribute("last", last);
  System.out.println(list.size());
  request.getRequestDispatcher("kehudangan.jsp").forward(request,
    response);
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException
  *             if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

UpdateServlet.java

package com.it.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
/**
 * Servlet implementation class UpdateServlet
 */
public class UpdateServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
 /**
  * @see HttpServlet#HttpServlet()
  */
 public UpdateServlet() {
  super();
  // TODO Auto-generated constructor stub
 }
 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doPost(request, response);
 }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=utf-8");
  String bh = request.getParameter("kh_bh");
  String bm = request.getParameter("kh_bm");
  String mc = request.getParameter("kh_mc");
  String jc = request.getParameter("kh_jc");
  String dh = request.getParameter("kh_dh");
  String dz = request.getParameter("kh_dz");
  String lxr = request.getParameter("kh_lxr");
  String email = request.getParameter("kh_email");
  String cz = request.getParameter("kh_cz");
  Kehudangan kh = new Kehudangan(bh, bm, mc, jc, dh, dz, lxr, email, cz);
  int flag = 1;
  try {
   new KehudanganDAO().updKehudangan(kh);
  } catch (Exception e) {
   flag = 0;
  }
  // 写一个参数给ajax。
  response.getWriter().print(flag);
 }
}

UpdPwdServlet.java

package com.it.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.it.dao.UserInfoDAO;
public class UpdPwdServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public UpdPwdServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  System.out.println("=================2=================");
  String user_id=request.getParameter("username");
  String user_pwd=request.getParameter("userpwd");
  String newpwd=request.getParameter("newpwd");
  //调用子dao中的修改密码方法   
  int flag=new UserInfoDAO().updUserInfo(user_id, user_pwd, newpwd);
  System.out.println("============"+flag);
  //缓存。
  response.getWriter().print(flag);
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

UpdServlet.java

package com.it.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.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
public class UpdServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public UpdServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  System.out.println("===============1===================");
  request.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=utf-8");
  String bh=request.getParameter("kh_bh");
  String bm=request.getParameter("kh_bm");
  String mc=request.getParameter("kh_mc");
  String jc=request.getParameter("kh_jc");
  String dh=request.getParameter("kh_dh");
  String dz=request.getParameter("kh_dz");
  String lxr=request.getParameter("kh_lxr");
  String email=request.getParameter("kh_email");
  String cz=request.getParameter("kh_cz");
  Kehudangan kh=new Kehudangan(bh,bm,mc,jc,dh,dz,lxr,email,cz);
  int flag=1;
  try {
   new KehudanganDAO().updKehudangan(kh);
  } catch (Exception e) {
   flag=0;
  }
  //写一个参数给ajax。
  response.getWriter().print(flag);
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

---

本文章采用 知识共享署名2.5中国大陆许可协议 进行许可,欢迎转载,演绎或用于商业目的。

---

二维码加载中...

扫一扫移动端访问O(∩_∩)O

发表评论

53 + 78 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交
正在加载中……